MCPcopy
hub / github.com/zu1k/proxypool / setupRouter

Function setupRouter

api/router.go:21–197  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19var router *gin.Engine
20
21func setupRouter() {
22 gin.SetMode(gin.ReleaseMode)
23 router = gin.New()
24 router.Use(gin.Recovery())
25 temp, err := loadTemplate()
26 if err != nil {
27 panic(err)
28 }
29 router.SetHTMLTemplate(temp)
30
31 router.GET("/", func(c *gin.Context) {
32 c.HTML(http.StatusOK, "assets/html/index.html", gin.H{
33 "domain": config.Config.Domain,
34 "getters_count": cache.GettersCount,
35 "all_proxies_count": cache.AllProxiesCount,
36 "ss_proxies_count": cache.SSProxiesCount,
37 "ssr_proxies_count": cache.SSRProxiesCount,
38 "vmess_proxies_count": cache.VmessProxiesCount,
39 "trojan_proxies_count": cache.TrojanProxiesCount,
40 "useful_proxies_count": cache.UsefullProxiesCount,
41 "last_crawl_time": cache.LastCrawlTime,
42 "version": version,
43 })
44 })
45
46 router.GET("/clash", func(c *gin.Context) {
47 c.HTML(http.StatusOK, "assets/html/clash.html", gin.H{
48 "domain": config.Config.Domain,
49 })
50 })
51
52 router.GET("/surge", func(c *gin.Context) {
53 c.HTML(http.StatusOK, "assets/html/surge.html", gin.H{
54 "domain": config.Config.Domain,
55 })
56 })
57
58 router.GET("/clash/config", func(c *gin.Context) {
59 c.HTML(http.StatusOK, "assets/html/clash-config.yaml", gin.H{
60 "domain": config.Config.Domain,
61 })
62 })
63
64 router.GET("/surge/config", func(c *gin.Context) {
65 c.HTML(http.StatusOK, "assets/html/surge.conf", gin.H{
66 "domain": config.Config.Domain,
67 })
68 })
69
70 router.GET("/clash/proxies", func(c *gin.Context) {
71 proxyTypes := c.DefaultQuery("type", "")
72 proxyCountry := c.DefaultQuery("c", "")
73 proxyNotCountry := c.DefaultQuery("nc", "")
74 text := ""
75 if proxyTypes == "" && proxyCountry == "" && proxyNotCountry == "" {
76 text = cache.GetString("clashproxies")
77 if text == "" {
78 proxies := cache.GetProxies("proxies")

Callers 1

RunFunction · 0.85

Calls 12

ProvideMethod · 0.95
ProvideMethod · 0.95
ProvideMethod · 0.95
ProvideMethod · 0.95
ProvideMethod · 0.95
GetStringFunction · 0.92
GetProxiesFunction · 0.92
SetStringFunction · 0.92
loadTemplateFunction · 0.85
LenMethod · 0.80
StringMethod · 0.65
LinkMethod · 0.65

Tested by

no test coverage detected