package main import ( // "flag" // "fmt" "embed" "fmt" "net/http" "strings" "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin" "github.com/google/uuid" ) //go:embed toe var staticFiles embed.FS func SetCustomContentType() gin.HandlerFunc { return func(c *gin.Context) { requestPath := c.Request.URL.Path if strings.Contains(requestPath, ".") { c.Header("Cache-Control", "public, max-age=31536000, immutable") } if strings.HasPrefix(requestPath, "/tic/tac/toe") && !strings.Contains(requestPath, ".") { c.Header("Content-Type", "text/html; charset=UTF-8") } else if strings.HasSuffix(requestPath, ".ico") { c.Header("Content-Type", "image/svg+xml") } else if strings.HasSuffix(requestPath, ".js") { c.Header("Content-Type", "application/javascript") } else if strings.HasSuffix(requestPath, ".css") { c.Header("Content-Type", "text/css") } c.Next() } } var favicon = "" func main() { embeddedFilesSystem := http.FS(staticFiles) router := gin.Default() router.Use(SetCustomContentType()) router.Use(gzip.Gzip(gzip.DefaultCompression)) router.GET("/", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/tic/tac/toe/index") }) router.GET("/favicon.ico", func(c *gin.Context) { c.String(http.StatusOK, favicon) }) router.GET("/multiplayer", multiplayer) router.StaticFS("/tic/tac", embeddedFilesSystem) router.Run(":8080") } func multiplayer(c *gin.Context) { if c.GetHeader("Accept") == "*/*" { c.String(http.StatusTeapot, "Preload not allowed") } u, err := uuid.NewV7() if err != nil { fmt.Println("Ошибка:", err) return } c.String(http.StatusOK, fmt.Sprintf("ToDo\nUUID7: %s", u.String())) }