mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
chore: coding style (#4082)
This commit is contained in:
@@ -30,9 +30,8 @@ var (
|
||||
ErrUnknownCode = errors.New("unknown status code")
|
||||
|
||||
//go:embed periodscript.lua
|
||||
periodScript string
|
||||
|
||||
scriptPeriod = redis.NewScript(periodScript)
|
||||
periodLuaScript string
|
||||
periodScript = redis.NewScript(periodLuaScript)
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -73,7 +72,7 @@ func (h *PeriodLimit) Take(key string) (int, error) {
|
||||
|
||||
// TakeCtx requests a permit with context, it returns the permit state.
|
||||
func (h *PeriodLimit) TakeCtx(ctx context.Context, key string) (int, error) {
|
||||
resp, err := h.limitStore.ScriptRunCtx(ctx, scriptPeriod, []string{h.keyPrefix + key}, []string{
|
||||
resp, err := h.limitStore.ScriptRunCtx(ctx, periodScript, []string{h.keyPrefix + key}, []string{
|
||||
strconv.Itoa(h.quota),
|
||||
strconv.Itoa(h.calcExpireSeconds()),
|
||||
})
|
||||
|
||||
@@ -11,4 +11,4 @@ elseif current == limit then
|
||||
return 2
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
@@ -23,9 +23,8 @@ const (
|
||||
|
||||
var (
|
||||
//go:embed tokenscript.lua
|
||||
tokenScript string
|
||||
|
||||
scriptToken = redis.NewScript(tokenScript)
|
||||
tokenLuaScript string
|
||||
tokenScript = redis.NewScript(tokenLuaScript)
|
||||
)
|
||||
|
||||
// A TokenLimiter controls how frequently events are allowed to happen with in one second.
|
||||
@@ -88,7 +87,7 @@ func (lim *TokenLimiter) reserveN(ctx context.Context, now time.Time, n int) boo
|
||||
}
|
||||
|
||||
resp, err := lim.store.ScriptRunCtx(ctx,
|
||||
scriptToken,
|
||||
tokenScript,
|
||||
[]string{
|
||||
lim.tokenKey,
|
||||
lim.timestampKey,
|
||||
|
||||
@@ -28,4 +28,4 @@ end
|
||||
redis.call("setex", KEYS[1], ttl, new_tokens)
|
||||
redis.call("setex", KEYS[2], ttl, now)
|
||||
|
||||
return allowed
|
||||
return allowed
|
||||
Reference in New Issue
Block a user