mirror of
https://github.com/JustKato/drive-health.git
synced 2026-04-30 01:42:29 +03:00
Implemented the hardware service
+ Started working on web interface
This commit is contained in:
34
lib/web/api.go
Normal file
34
lib/web/api.go
Normal 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
7
lib/web/frontend.go
Normal 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
16
lib/web/health.go
Normal 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
19
lib/web/net.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user