2024-01-20 01:27:10 +02:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
2024-01-20 01:40:55 +02:00
|
|
|
"tea.chunkbyte.com/kato/drive-health/lib/svc"
|
2024-01-20 01:27:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-01-20 01:40:55 +02:00
|
|
|
api.GET("/snapshots", func(ctx *gin.Context) {
|
|
|
|
snapshots := svc.GetHardwareSnapshot()
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, snapshots)
|
|
|
|
})
|
|
|
|
|
2024-01-20 01:27:10 +02:00
|
|
|
}
|