From 4dafaacf8df56f638c7e153fdcb53dad0cce26c5 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Tue, 13 Dec 2022 08:07:11 +0800 Subject: [PATCH] esbuild embed --- main.go | 17 +++++++++++++++++ pkg/api/api.go | 5 ----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 210bceb..e03bb8a 100644 --- a/main.go +++ b/main.go @@ -3,11 +3,28 @@ package main import ( "ais/pkg/api" + _ "embed" + + "github.com/gin-gonic/gin" ) +//go:embed web/public/index.html +var indexhtml string + +//go:embed web/public/ais.js +var aisjs string func main() { router := api.NewAPI() + router.GET("/", func(c *gin.Context) { + c.Header("Content-Type", "text/html") + c.String(200, indexhtml) + }) + router.GET("/ais.js", func(c *gin.Context) { + c.Header("Content-Type", "text/javascript") + c.String(200, aisjs) + }) + router.Run(":8888") } diff --git a/pkg/api/api.go b/pkg/api/api.go index 1330f18..20bd7e8 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -60,11 +60,6 @@ func NewAPI() *gin.Engine { store := cookie.NewStore([]byte("Miku saves the world!")) router.Use(sessions.Sessions("ais", store)) - // entry point html - router.GET("/", func(c *gin.Context) { - c.File("./web/public/index.html") - }) - group := router.Group("/api") // json error middleware