go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

token limit support context

Open sado0823 opened this issue 1 year ago β€’ 4 comments

supported token limiter with context using option func mode, if not set, using context.backgroud as default

        // example
        s, err := miniredis.Run()
	assert.Nil(t, err)

        l := NewTokenLimiter(rate, burst, redis.New(s.Addr()), "tokenlimit")
	defer s.Close()
        
        // use cuxtom ctx
	ctx, cancel := context.WithCancel(context.Background())
	ok := l.Allow(WithTokenCtx(ctx))
	assert.True(t, ok)

sado0823 avatar Aug 31 '22 10:08 sado0823

@kevwan

sado0823 avatar Sep 01 '22 09:09 sado0823

Bot detected the issue body's language is not English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ


@kevwan

Issues-translate-bot avatar Sep 01 '22 09:09 Issues-translate-bot

Recommend to use AllowCtx(ctx), and AllowNCtx(ctx...).

kevwan avatar Sep 10 '22 07:09 kevwan

try with AllowCtx(ctx), and AllowNCtx(ctx...), please review it. @kevwan

sado0823 avatar Sep 21 '22 08:09 sado0823