github.com/ztalab/ZACA@v0.0.1/util/cache.go (about) 1 package util 2 3 import ( 4 "crypto/sha1" 5 "encoding/hex" 6 "math" 7 "strconv" 8 "time" 9 10 "github.com/gin-gonic/gin" 11 "github.com/ztalab/ZACA/pkg/memorycacher" 12 ) 13 14 var MapCache *memorycacher.Cache 15 16 func init() { 17 MapCache = memorycacher.New(2*time.Minute, 10*time.Minute, math.MaxInt64) 18 } 19 20 func GinRequestHash(g *gin.Context) string { 21 url := g.Request.URL.String() 22 body := g.Request.ContentLength 23 24 sha := sha1.Sum([]byte(url + strconv.FormatInt(body, 10))) 25 26 return hex.EncodeToString(sha[:]) 27 }