mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-06-17 12:43:18 +08:00
refactor
This commit is contained in:
51
server/route.go
Normal file
51
server/route.go
Normal file
@ -0,0 +1,51 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/bestnite/sub2clash/config"
|
||||
"github.com/bestnite/sub2clash/constant"
|
||||
"github.com/bestnite/sub2clash/model"
|
||||
"github.com/bestnite/sub2clash/server/handler"
|
||||
"github.com/bestnite/sub2clash/server/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
//go:embed static
|
||||
var staticFiles embed.FS
|
||||
|
||||
func SetRoute(r *gin.Engine) {
|
||||
r.Use(middleware.ZapLogger())
|
||||
|
||||
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 := constant.Version
|
||||
c.HTML(
|
||||
200, "index.html", gin.H{
|
||||
"Version": version,
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
r.GET("/clash", handler.SubHandler(model.Clash, config.GlobalConfig.ClashTemplate))
|
||||
r.GET("/meta", handler.SubHandler(model.ClashMeta, config.GlobalConfig.MetaTemplate))
|
||||
r.GET("/s/:hash", handler.GetRawConfHandler)
|
||||
r.POST("/short", handler.GenerateLinkHandler)
|
||||
r.PUT("/short", handler.UpdateLinkHandler)
|
||||
r.GET("/short", handler.GetRawConfUriHandler)
|
||||
}
|
Reference in New Issue
Block a user