1
0
mirror of https://github.com/bestnite/sub2clash.git synced 2025-12-16 02:50:16 +00:00

feat: 修改短链

update: dockerfile,workflow
This commit is contained in:
2024-03-13 13:30:45 +08:00
parent 1d9de31f47
commit 14c3b97ed2
19 changed files with 609 additions and 527 deletions

43
api/handler/clash.go Normal file
View File

@@ -0,0 +1,43 @@
package handler
import (
"net/http"
"sub2clash/config"
"sub2clash/model"
"sub2clash/validator"
"github.com/gin-gonic/gin"
"gopkg.in/yaml.v3"
)
func SubmodHandler(c *gin.Context) {
// 从请求中获取参数
query, err := validator.ParseQuery(c)
if err != nil {
c.String(http.StatusBadRequest, err.Error())
return
}
sub, err := BuildSub(model.Clash, query, config.Default.ClashTemplate)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
// 输出
if query.NodeListMode {
nodelist := model.NodeList{}
nodelist.Proxies = sub.Proxies
marshal, err := yaml.Marshal(nodelist)
if err != nil {
c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
return
}
c.String(http.StatusOK, string(marshal))
return
}
marshal, err := yaml.Marshal(sub)
if err != nil {
c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
return
}
c.String(http.StatusOK, string(marshal))
}