Api and Frontend

+ Snapshot get API
+ Frontend Starting
This commit is contained in:
2024-01-20 01:40:55 +02:00
parent 4352c398c1
commit 71d4eb6cc3
4 changed files with 109 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin"
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
"tea.chunkbyte.com/kato/drive-health/lib/svc"
)
func setupApi(r *gin.Engine) {
@@ -31,4 +32,10 @@ func setupApi(r *gin.Engine) {
})
})
api.GET("/snapshots", func(ctx *gin.Context) {
snapshots := svc.GetHardwareSnapshot()
ctx.JSON(http.StatusOK, snapshots)
})
}

View File

@@ -1,7 +1,31 @@
package web
import "github.com/gin-gonic/gin"
import (
"net/http"
"github.com/gin-gonic/gin"
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
)
func setupFrontend(r *gin.Engine) {
r.LoadHTMLGlob("templates/*")
r.Static("/static", "./static")
// Set up a route for the root URL
r.GET("/", func(c *gin.Context) {
hardDrives, err := hardware.GetSystemHardDrives()
if err != nil {
c.AbortWithStatus(500)
}
for _, hdd := range hardDrives {
hdd.GetTemperature(true)
}
// Render the HTML template
c.HTML(http.StatusOK, "index.html", gin.H{
"drives": hardDrives,
})
})
}