diff --git a/docs/proxy.yaml b/docs/proxy.yaml index 930cde474840485118d2011a96c23f6aed60e34e..9a1ed5966a871db681bd5e4ae237bc4e766ee107 100644 --- a/docs/proxy.yaml +++ b/docs/proxy.yaml @@ -1,4 +1,5 @@ { + "uuid": "sdfasd", "url":"https://apaas.wodcloud.com/cigservice/baseservice/fillder/turnover?applyId=0419f3e1-8e16-4e5e-a187-1760364c04e2", "method":"GET", "params":null diff --git a/src/config/conf.go b/src/config/conf.go index 757eb2bcbfe833850bdc87d9c7910cd783ce146e..3f2af639f8d32c563fcc790bd7bdc7395eee94c0 100644 --- a/src/config/conf.go +++ b/src/config/conf.go @@ -7,6 +7,7 @@ var ( ) var ProxyConf = struct { + UUID string `json:"uuid"` Url string `json:"url"` Method string `json:"method"` Params []Param `json:"params"` diff --git a/src/handler/counthandler.go b/src/handler/counthandler.go index 30bb14a67e5972d88ce9556659f377c9dddbb1fc..0072b9644e8be887cf363bda407cbcda3ab28e36 100644 --- a/src/handler/counthandler.go +++ b/src/handler/counthandler.go @@ -1,17 +1,20 @@ package handler import ( + "fmt" "github.com/gin-gonic/gin" + "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/client" + "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/config" ) func GetCount(c *gin.Context) { - //redis, err := client.GetRedisClient() - //if err != nil { - // c.Error(err) - //} - //ic, err := redis.Get(fmt.Sprintf("%s%s", config.ProxyHost, config.ProxyPath)) - //c.JSON(200, gin.H{ - // "Key": fmt.Sprintf("%s%s", config.ProxyHost, config.ProxyPath), - // "Count": ic, - //}) + redis, err := client.GetRedisClient() + if err != nil { + c.Error(err) + } + ic, err := redis.Get("bgproxy" + config.ProxyConf.UUID) + c.JSON(200, gin.H{ + "Key": fmt.Sprintf("bgproxy" + config.ProxyConf.UUID), + "Count": ic, + }) } diff --git a/src/handler/proxyhandler.go b/src/handler/proxyhandler.go index c08b94d64c927781e09c5f4a135e1ee2ea91ff79..eecdd5d20d02598bccd8591c0ddbf3d9fd19b6c5 100644 --- a/src/handler/proxyhandler.go +++ b/src/handler/proxyhandler.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/client" "net/http" "github.com/vulcand/oxy/forward" @@ -71,12 +72,11 @@ func getRequestURI(req *http.Request) string { 计数 */ func count() error { - //redis, err := client.GetRedisClient() - //if err != nil { - // return err - //} - //ic, err := redis.Incr(fmt.Sprintf("%s%s", config.ProxyHost, config.ProxyPath)) - //_, err = ic.Result() - //return err - return nil + redis, err := client.GetRedisClient() + if err != nil { + return err + } + ic, err := redis.Incr("bgproxy" + config.ProxyConf.UUID) + _, err = ic.Result() + return err }