2023-09-12 06:40:24 -04:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2023-09-16 09:46:59 -04:00
|
|
|
"embed"
|
2023-09-12 06:40:24 -04:00
|
|
|
"github.com/gin-gonic/gin"
|
2023-09-16 09:46:59 -04:00
|
|
|
"html/template"
|
2023-09-12 12:46:17 -04:00
|
|
|
"sub2clash/api/controller"
|
2023-09-13 01:47:22 -04:00
|
|
|
"sub2clash/middleware"
|
2023-09-12 06:40:24 -04:00
|
|
|
)
|
|
|
|
|
2023-09-16 09:46:59 -04:00
|
|
|
//go:embed templates/*
|
|
|
|
var templates embed.FS
|
|
|
|
|
2023-09-12 06:40:24 -04:00
|
|
|
func SetRoute(r *gin.Engine) {
|
2023-09-13 01:47:22 -04:00
|
|
|
r.Use(middleware.ZapLogger())
|
2023-09-16 09:46:59 -04:00
|
|
|
// 使用内嵌的模板文件
|
|
|
|
r.SetHTMLTemplate(template.Must(template.New("").ParseFS(templates, "templates/*")))
|
|
|
|
r.GET(
|
|
|
|
"/", func(c *gin.Context) {
|
|
|
|
c.HTML(200, "index.html", nil)
|
|
|
|
},
|
|
|
|
)
|
2023-09-12 06:40:24 -04:00
|
|
|
r.GET(
|
|
|
|
"/clash", func(c *gin.Context) {
|
|
|
|
controller.SubmodHandler(c)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
r.GET(
|
|
|
|
"/meta", func(c *gin.Context) {
|
|
|
|
controller.SubHandler(c)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|