Skip to content

Commit

Permalink
update: Web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nitezs committed Sep 16, 2023
1 parent e64bc9b commit 8833e03
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions api/route.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package api

import (
"embed"
"github.com/gin-gonic/gin"
"html/template"
"sub2clash/api/controller"
"sub2clash/middleware"
)

//go:embed templates/*
var templates embed.FS

func SetRoute(r *gin.Engine) {
r.Use(middleware.ZapLogger())
// 使用内嵌的模板文件
r.SetHTMLTemplate(template.Must(template.New("").ParseFS(templates, "templates/*")))
r.GET(
"/", func(c *gin.Context) {
c.HTML(200, "index.html", nil)
},
)
r.GET(
"/clash", func(c *gin.Context) {
controller.SubmodHandler(c)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// LoadTemplate 加载模板
// template 模板文件名
// templates 模板文件名
func LoadTemplate(template string) ([]byte, error) {
tPath := filepath.Join("templates", template)
if _, err := os.Stat(tPath); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion validator/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type SubQuery struct {
Proxy string `form:"proxy" binding:""`
Proxies []string `form:"-" binding:""`
Refresh bool `form:"refresh,default=false" binding:""`
Template string `form:"template" binding:""`
Template string `form:"templates" binding:""`
RuleProvider string `form:"ruleProvider" binding:""`
RuleProviders []RuleProviderStruct `form:"-" binding:""`
Rule string `form:"rule" binding:""`
Expand Down

0 comments on commit 8833e03

Please sign in to comment.