From cd1fc2a48b122cfbbf8a04b31edee45c8627d045 Mon Sep 17 00:00:00 2001
From: shaoyongjun <mylomen.shao@freebrio.com>
Date: Mon, 29 Apr 2024 23:59:09 +0800
Subject: [PATCH] to:sync

---
 main.go                  |  3 ++-
 static/init.go           | 54 ++++++++++++++++++++++++++++++++++++++++
 {apps => static}/page.go | 10 +++++---
 3 files changed, 62 insertions(+), 5 deletions(-)
 create mode 100644 static/init.go
 rename {apps => static}/page.go (72%)

diff --git a/main.go b/main.go
index e3c90ca..3e3295a 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
 	"ai-gateway/common/constant"
 	"ai-gateway/common/filter"
 	"ai-gateway/common/utils"
+	"ai-gateway/static"
 	"context"
 	"fmt"
 	"github.com/labstack/echo/v4"
@@ -56,7 +57,7 @@ func main() {
 	//user
 	apps.InitUserGroup(e.Group("/v1/user/"))
 
-	apps.InitStaticGroup(e.Group("/v1/static/"))
+	static.InitStaticGroup(e.Group("/v1/static/"))
 
 	//ai
 	apps.InitAiGroup(e.Group("/v1/ai/", func(next echo.HandlerFunc) echo.HandlerFunc {
diff --git a/static/init.go b/static/init.go
new file mode 100644
index 0000000..8f3d9b9
--- /dev/null
+++ b/static/init.go
@@ -0,0 +1,54 @@
+package static
+
+import (
+	"embed"
+)
+import _ "embed"
+
+//go:embed *.html
+var pageList embed.FS
+
+//go:embed img/*.jpeg
+var imgList embed.FS
+
+//go:embed css/*.css
+var cssList embed.FS
+
+var pageMap = initPageMap()
+var imgMap = initImgMap
+var cssMap = initCssMap()
+
+func initPageMap() map[string][]byte {
+	var pageMap = make(map[string][]byte, 8)
+
+	//login.html
+	data, err := pageList.ReadFile("login.html")
+	if err == nil {
+		pageMap["login.html"] = data
+	}
+
+	return pageMap
+}
+
+func initImgMap() map[string][]byte {
+	var dataMap = make(map[string][]byte, 8)
+
+	//login.html
+	data, err := imgList.ReadFile("003.jpeg")
+	if err == nil {
+		dataMap["003.jpeg"] = data
+	}
+
+	return dataMap
+}
+
+func initCssMap() map[string][]byte {
+	var dataMap = make(map[string][]byte, 8)
+	//login.html
+	data, err := cssList.ReadFile("login.css")
+	if err == nil {
+		dataMap["login.css"] = data
+	}
+
+	return dataMap
+}
diff --git a/apps/page.go b/static/page.go
similarity index 72%
rename from apps/page.go
rename to static/page.go
index 69f2c7d..93278a5 100644
--- a/apps/page.go
+++ b/static/page.go
@@ -1,4 +1,4 @@
-package apps
+package static
 
 import (
 	"github.com/labstack/echo/v4"
@@ -6,20 +6,22 @@ import (
 )
 
 func InitStaticGroup(g *echo.Group) {
+
 	g.GET("login.html", func(c echo.Context) error {
 		c.Response().Header().Set("Content-Type", "text/html; charset=utf-8")
 		c.Response().Header().Set("Cache-Control", "max-age=3600")
-		return c.File("static/login.html")
+
+		return c.Blob(http.StatusOK, "text/html; charset=utf-8", pageMap["login.html"])
 	})
 
 	g.GET("css/login.css", func(c echo.Context) error {
 		c.Response().Header().Set("Cache-Control", "max-age=3600")
-		return c.File("static/css/login.css")
+		return c.Blob(http.StatusOK, "text/html; charset=utf-8", cssMap["login.css"])
 	})
 
 	g.GET("img/003.jpeg", func(c echo.Context) error {
 		c.Response().Header().Set("Cache-Control", "max-age=3600")
-		return c.File("static/img/003.jpeg")
+		return c.Blob(http.StatusOK, "text/html; charset=utf-8", cssMap["login.css"])
 	})
 
 	g.GET("/aa", func(c echo.Context) error {