go-zero
go-zero copied to clipboard
token limit support context
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)
@kevwan
Bot detected the issue body's language is not English, translate it automatically. π―ππ»π§βπ€βπ§π«π§πΏβπ€βπ§π»π©πΎβπ€βπ¨πΏπ¬πΏ
@kevwan
Recommend to use AllowCtx(ctx), and AllowNCtx(ctx...).
try with AllowCtx(ctx), and AllowNCtx(ctx...), please review it. @kevwan