1
0
mirror of https://github.com/bestnite/sub2clash.git synced 2025-12-15 18:40:16 +00:00

feat: 增加输出NodeList选项

This commit is contained in:
2023-09-25 15:43:21 +08:00
parent ad7d2b98f6
commit 6a5cfd35c9
13 changed files with 741 additions and 712 deletions

View File

@@ -4,23 +4,40 @@ import (
"embed"
"github.com/gin-gonic/gin"
"html/template"
"log"
"net/http"
"sub2clash/api/controller"
"sub2clash/config"
"sub2clash/middleware"
)
//go:embed templates/*
var templates embed.FS
//go:embed static
var staticFiles embed.FS
func SetRoute(r *gin.Engine) {
r.Use(middleware.ZapLogger())
// 使用内嵌的模板文件
r.SetHTMLTemplate(template.Must(template.New("").ParseFS(templates, "templates/*")))
tpl, err := template.ParseFS(staticFiles, "static/*")
if err != nil {
log.Fatalf("Error parsing templates: %v", err)
}
r.SetHTMLTemplate(tpl)
r.GET(
"/static/*filepath", func(c *gin.Context) {
c.FileFromFS("static/"+c.Param("filepath"), http.FS(staticFiles))
},
)
r.GET(
"/", func(c *gin.Context) {
version := config.Version
if len(config.Version) > 7 {
version = config.Version[:7]
}
c.HTML(
200, "index.html", gin.H{
"Version": config.Version,
"Version": version,
},
)
},