From 5fde0b6658a75c6b2f3fcf280a53f46e0da3a4fc Mon Sep 17 00:00:00 2001 From: zu1k Date: Fri, 4 Sep 2020 17:13:19 +0800 Subject: [PATCH] add link for all proxies --- api/router.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api/router.go b/api/router.go index 2290182..209973e 100644 --- a/api/router.go +++ b/api/router.go @@ -4,6 +4,7 @@ import ( "html/template" "net/http" "os" + "strconv" "github.com/gin-gonic/gin" _ "github.com/heroku/x/hmetrics/onload" @@ -181,6 +182,18 @@ func setupRouter() { } c.String(200, vmessSub.Provide()) }) + router.GET("/link/:id", func(c *gin.Context) { + idx := c.Param("id") + proxies := cache.GetProxies("allproxies") + id, err := strconv.Atoi(idx) + if err != nil { + c.String(500, err.Error()) + } + if id >= proxies.Len() { + c.String(500, "id too big") + } + c.String(200, proxies[id].Link()) + }) } func Run() {