Implemented the hardware service

+ Started working on web interface
This commit is contained in:
2024-01-20 01:27:10 +02:00
parent fbee33bf00
commit 81ca5ddf28
13 changed files with 398 additions and 12 deletions

34
lib/web/api.go Normal file
View File

@@ -0,0 +1,34 @@
package web
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
)
func setupApi(r *gin.Engine) {
api := r.Group("/v1/api")
api.GET("/disks", func(ctx *gin.Context) {
// Fetch the disk list
disks, err := hardware.GetSystemHardDrives()
if err != nil {
ctx.Error(err)
}
if ctx.Request.URL.Query().Get("temp") != "" {
for _, d := range disks {
temp := d.GetTemperature(true)
fmt.Printf("Disk Temp: %v", temp)
}
}
ctx.JSON(http.StatusOK, gin.H{
"message": "Disk List",
"disks": disks,
})
})
}

7
lib/web/frontend.go Normal file
View File

@@ -0,0 +1,7 @@
package web
import "github.com/gin-gonic/gin"
func setupFrontend(r *gin.Engine) {
}

16
lib/web/health.go Normal file
View File

@@ -0,0 +1,16 @@
package web
import (
"net/http"
"github.com/gin-gonic/gin"
)
func setupHealth(r *gin.Engine) {
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "Pong",
})
})
}

19
lib/web/net.go Normal file
View File

@@ -0,0 +1,19 @@
package web
import (
"github.com/gin-gonic/gin"
)
func SetupRouter() *gin.Engine {
// Initialize the Gin engine
r := gin.Default()
// Setup Health Pings
setupHealth(r)
// Setup Api
setupApi(r)
// Setup Frontend
setupFrontend(r)
return r
}