1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-25 08:50:54 -05:00
sub2clash/api/route.go

49 lines
850 B
Go
Raw Permalink Normal View History

2023-09-12 06:40:24 -04:00
package api
import (
"embed"
2023-09-12 06:40:24 -04:00
"github.com/gin-gonic/gin"
"html/template"
2023-09-12 12:46:17 -04:00
"sub2clash/api/controller"
"sub2clash/config"
2023-09-13 01:47:22 -04:00
"sub2clash/middleware"
2023-09-12 06:40:24 -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())
// 使用内嵌的模板文件
r.SetHTMLTemplate(template.Must(template.New("").ParseFS(templates, "templates/*")))
r.GET(
"/", func(c *gin.Context) {
c.HTML(
200, "index.html", gin.H{
"Version": config.Version,
},
)
},
)
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)
},
)
2023-09-17 03:52:37 -04:00
r.POST(
"/short", func(c *gin.Context) {
controller.ShortLinkGenHandler(c)
},
)
r.GET(
"/s/:hash", func(c *gin.Context) {
controller.ShortLinkGetHandler(c)
},
)
2023-09-12 06:40:24 -04:00
}