2024-06-03 09:24:18 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-06-03 10:44:16 +02:00
|
|
|
"embed"
|
2024-06-03 09:24:18 +02:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
WebPort string = "8080"
|
|
|
|
)
|
|
|
|
|
2024-06-03 10:44:16 +02:00
|
|
|
//go:embed templates/*
|
|
|
|
var templatesFolder embed.FS
|
|
|
|
|
2024-06-03 09:24:18 +02:00
|
|
|
func WebServer() {
|
|
|
|
p := viper.GetString("Server.WebPort")
|
|
|
|
if p != "" {
|
|
|
|
WebPort = p
|
|
|
|
}
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
r := gin.Default()
|
2024-06-03 10:44:16 +02:00
|
|
|
LoadHTMLFromEmbedFS(r, templatesFolder, "templates/*.html")
|
|
|
|
r.StaticFileFS("/style.css", "./templates/style.css", http.FS(templatesFolder))
|
2024-06-03 09:24:18 +02:00
|
|
|
r.GET("/", getRoot)
|
|
|
|
r.Run(":" + WebPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getRoot(c *gin.Context) {
|
2024-06-03 10:44:16 +02:00
|
|
|
c.HTML(http.StatusOK, "templates/index.html", gin.H{
|
|
|
|
"UserAgent": c.Request.UserAgent(),
|
|
|
|
"Clients": clientList,
|
|
|
|
})
|
2024-06-03 09:24:18 +02:00
|
|
|
}
|