mylomen-server/static/static_router.go

82 lines
2.6 KiB
Go
Raw Normal View History

2024-04-29 23:59:09 +08:00
package static
2024-04-29 23:09:19 +08:00
import (
"github.com/labstack/echo/v4"
"net/http"
)
2024-05-21 17:18:47 +08:00
func Favicon(c echo.Context) error {
c.Response().Header().Set("Cache-Control", "max-age=3600")
return c.Blob(http.StatusOK, "image/png", imgMap["favicon.ico"])
}
2024-04-30 22:11:21 +08:00
func Login(c echo.Context) error {
c.Response().Header().Set("Cache-Control", "max-age=3600")
return c.Blob(http.StatusOK, "text/html; charset=utf-8", pageMap["login.html"])
}
func Chat(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.Blob(http.StatusOK, "text/html; charset=utf-8", pageMap["ai-chat.html"])
}
2024-05-20 10:19:46 +08:00
func Chat1(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.Blob(http.StatusOK, "text/html; charset=utf-8", pageMap["ai-chat1.html"])
}
func Chat2(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.Blob(http.StatusOK, "text/html; charset=utf-8", pageMap["ai-chat2.html"])
}
2024-05-21 17:18:47 +08:00
func Chat3(c echo.Context) error {
c.Response().Header().Set("Content-Type", "text/html; charset=utf-8")
2024-05-21 18:31:32 +08:00
c.Response().Header().Set("Cache-Control", "max-age=1")
2024-05-21 17:18:47 +08:00
return c.Blob(http.StatusOK, "text/html; charset=utf-8", pageMap["index_ollama.html"])
}
2024-04-29 23:09:19 +08:00
func InitStaticGroup(g *echo.Group) {
2024-04-29 23:59:09 +08:00
2024-04-29 23:09:19 +08:00
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")
2024-04-29 23:59:09 +08:00
return c.Blob(http.StatusOK, "text/html; charset=utf-8", pageMap["login.html"])
2024-04-29 23:09:19 +08:00
})
2024-05-21 17:18:47 +08:00
g.GET("css/:name", func(c echo.Context) error {
cssName := c.Param("name")
2024-05-21 18:31:32 +08:00
c.Response().Header().Set("Cache-Control", "max-age=1")
2024-05-21 17:18:47 +08:00
data, _ := cssMap[cssName]
2024-04-30 00:08:26 +08:00
return c.Blob(http.StatusOK, "text/css; charset=utf-8", data)
2024-04-29 23:09:19 +08:00
})
2024-05-21 17:18:47 +08:00
g.GET("img/:name", func(c echo.Context) error {
imgName := c.Param("name")
2024-04-29 23:09:19 +08:00
c.Response().Header().Set("Cache-Control", "max-age=3600")
2024-05-21 17:18:47 +08:00
return c.Blob(http.StatusOK, "image/jpeg", imgMap[imgName])
2024-04-29 23:09:19 +08:00
})
2024-05-21 17:18:47 +08:00
g.GET("js/:name", func(c echo.Context) error {
jsName := c.Param("name")
2024-05-21 18:31:32 +08:00
c.Response().Header().Set("Cache-Control", "max-age=1")
2024-05-21 17:18:47 +08:00
return c.Blob(http.StatusOK, "text/javaScript", jsMap[jsName])
})
g.GET("page/:name", func(c echo.Context) error {
pageName := c.Param("name")
c.Response().Header().Set("Cache-Control", "max-age=3600")
data, _ := pageMap[pageName]
return c.Blob(http.StatusOK, "text/html; charset=utf-8", data)
2024-04-29 23:09:19 +08:00
})
}