I want to do a A/B test in a Gin's middleware, I want to pass url:usermeta
as a key-value to the A/B test service. How can I achieve this goal?Or any other grace way?
I suppose you want to add a new functional middleware and test it in A/B style.
func ServiceMiddleWare() gin.HandleFunc {
return func(c *gin.Context){
r := rand.New(rand.NewSource(time.Now().UnixNano()))
if r.Intn(100) < 50 {
c.Next()
return
}
// service_logic
fmt.Println("add a new service")
c.Next()
}
}
Use
c.FullPath()
for get current URL path
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.