mirror of
https://github.com/JustKato/drive-health.git
synced 2026-04-30 01:42:29 +03:00
Implemented frontend
+ Graph Generation as images for frontend performance + A new decent style
This commit is contained in:
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,6 +13,44 @@ import (
|
||||
func setupApi(r *gin.Engine) {
|
||||
api := r.Group("/api/v1")
|
||||
|
||||
api.GET("/disks/:diskid/chart", func(ctx *gin.Context) {
|
||||
diskIDString := ctx.Param("diskid")
|
||||
diskId, err := strconv.Atoi(diskIDString)
|
||||
if err != nil {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
"error": err.Error(),
|
||||
"message": "Invalid Disk ID",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
graphData, err := svc.GetDiskGraphImage(diskId, nil, nil)
|
||||
if err != nil {
|
||||
ctx.AbortWithStatusJSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
"message": "Graph generation issue",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Set the content type header
|
||||
ctx.Writer.Header().Set("Content-Type", "image/png")
|
||||
|
||||
// Write the image data to the response
|
||||
ctx.Writer.WriteHeader(http.StatusOK)
|
||||
_, err = graphData.WriteTo(ctx.Writer)
|
||||
if err != nil {
|
||||
ctx.AbortWithStatusJSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
"message": "Write error",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
api.GET("/disks", func(ctx *gin.Context) {
|
||||
|
||||
olderThan := time.Now().Add(time.Minute * time.Duration(10) * -1)
|
||||
|
||||
Reference in New Issue
Block a user