Files
oxTTT/server/main.go

38 lines
774 B
Go

package main
import (
// "flag"
// "fmt"
"embed"
"net/http"
"strings"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
//go:embed static
var staticFiles embed.FS
func SetCustomContentType() gin.HandlerFunc {
return func(c *gin.Context) {
requestPath := c.Request.URL.Path
if strings.HasPrefix(requestPath, "/l/static") {
c.Header("Content-Type", "text/html; charset=UTF-8")
}
c.Next()
}
}
func main() {
embeddedFilesSystem := http.FS(staticFiles)
router := gin.Default()
router.Use(SetCustomContentType())
router.Use(gzip.Gzip(gzip.DefaultCompression))
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
router.StaticFS("/l", embeddedFilesSystem)
router.Run(":8080")
}