Implemented frontend

+ Graph Generation as images for frontend performance
+ A new decent style
This commit is contained in:
2024-01-21 18:25:23 +02:00
parent eb94ce4552
commit 545eed44cd
7 changed files with 315 additions and 40 deletions

View File

@@ -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)