mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-12-15 18:40:16 +00:00
feat: 增加输出NodeList选项
This commit is contained in:
25
api/route.go
25
api/route.go
@@ -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,
|
||||
},
|
||||
)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user