Repository: zeromicro/go-zero
Pull request #4082 (2024-04-17 15:31:57)

chore: coding style

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/4082?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 95.16%. Comparing base [(`8690859`)](https://app.codecov.io/gh/zeromicro/go-zero/commit/8690859c7d1c9461bdc422c3c65608bde30904db?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) to head [(`950de56`)](https://app.codecov.io/gh/zeromicro/go-zero/pull/4082?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro).
> Report is 16 commits behind head on master.

<details><summary>Additional details and impacted files</summary>



| [Files](https://app.codecov.io/gh/zeromicro/go-zero/pull/4082?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) | Coverage Δ | |
|---|---|---|
| [core/bloom/bloom.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/4082?src=pr&el=tree&filepath=core%2Fbloom%2Fbloom.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-Y29yZS9ibG9vbS9ibG9vbS5nbw==) | `96.72% <100.00%> (+0.88%)` | :arrow_up: |
| [core/limit/periodlimit.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/4082?src=pr&el=tree&filepath=core%2Flimit%2Fperiodlimit.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-Y29yZS9saW1pdC9wZXJpb2RsaW1pdC5nbw==) | `90.00% <100.00%> (+0.63%)` | :arrow_up: |
| [core/limit/tokenlimit.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/4082?src=pr&el=tree&filepath=core%2Flimit%2Ftokenlimit.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-Y29yZS9saW1pdC90b2tlbmxpbWl0Lmdv) | `94.20% <100.00%> (+0.30%)` | :arrow_up: |
| [core/stores/redis/redislock.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/4082?src=pr&el=tree&filepath=core%2Fstores%2Fredis%2Fredislock.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-Y29yZS9zdG9yZXMvcmVkaXMvcmVkaXNsb2NrLmdv) | `84.21% <100.00%> (+2.81%)` | :arrow_up: |

... and [251 files with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/4082/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro)

</details>

Patch:
diff --git a/core/bloom/bloom.go b/core/bloom/bloom.go
index e47eb86f..68f22812 100644
--- a/core/bloom/bloom.go
+++ b/core/bloom/bloom.go
@@ -19,14 +19,12 @@ var (
 	ErrTooLargeOffset = errors.New("too large offset")
 
 	//go:embed setscript.lua
-	setScript string
-
-	scriptSet = redis.NewScript(setScript)
+	setLuaScript string
+	setScript    = redis.NewScript(setLuaScript)
 
 	//go:embed testscript.lua
-	testScript string
-
-	scriptTest = redis.NewScript(testScript)
+	testLuaScript string
+	testScript    = redis.NewScript(testLuaScript)
 )
 
 type (
@@ -126,7 +124,7 @@ func (r *redisBitSet) check(ctx context.Context, offsets []uint) (bool, error) {
 		return false, err
 	}
 
-	resp, err := r.store.ScriptRunCtx(ctx, scriptTest, []string{r.key}, args)
+	resp, err := r.store.ScriptRunCtx(ctx, testScript, []string{r.key}, args)
 	if errors.Is(err, redis.Nil) {
 		return false, nil
 	} else if err != nil {
@@ -158,7 +156,7 @@ func (r *redisBitSet) set(ctx context.Context, offsets []uint) error {
 		return err
 	}
 
-	_, err = r.store.ScriptRunCtx(ctx, scriptSet, []string{r.key}, args)
+	_, err = r.store.ScriptRunCtx(ctx, setScript, []string{r.key}, args)
 	if errors.Is(err, redis.Nil) {
 		return nil
 	}
diff --git a/core/bloom/setscript.lua b/core/bloom/setscript.lua
index 6d9d60f2..3bd391fd 100644
--- a/core/bloom/setscript.lua
+++ b/core/bloom/setscript.lua
@@ -1,3 +1,3 @@
 for _, offset in ipairs(ARGV) do
     redis.call("setbit", KEYS[1], offset, 1)
-end
+end
\ No newline at end of file
diff --git a/core/limit/periodlimit.go b/core/limit/periodlimit.go
index 070bb7f8..b7a3508b 100644
--- a/core/limit/periodlimit.go
+++ b/core/limit/periodlimit.go
@@ -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()),
 	})
diff --git a/core/limit/periodscript.lua b/core/limit/periodscript.lua
index c351c840..7caaabe0 100644
--- a/core/limit/periodscript.lua
+++ b/core/limit/periodscript.lua
@@ -11,4 +11,4 @@ elseif current == limit then
     return 2
 else
     return 0
-end
+end
\ No newline at end of file
diff --git a/core/limit/tokenlimit.go b/core/limit/tokenlimit.go
index 0070eca4..25c7ba0b 100644
--- a/core/limit/tokenlimit.go
+++ b/core/limit/tokenlimit.go
@@ -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,
diff --git a/core/limit/tokenscript.lua b/core/limit/tokenscript.lua
index b70ad1ee..ac39565f 100644
--- a/core/limit/tokenscript.lua
+++ b/core/limit/tokenscript.lua
@@ -28,4 +28,4 @@ end
 redis.call("setex", KEYS[1], ttl, new_tokens)
 redis.call("setex", KEYS[2], ttl, now)
 
-return allowed
+return allowed
\ No newline at end of file
diff --git a/core/stores/redis/delscript.lua b/core/stores/redis/delscript.lua
index e9aa40a2..7bcae4e7 100644
--- a/core/stores/redis/delscript.lua
+++ b/core/stores/redis/delscript.lua
@@ -2,4 +2,4 @@ if redis.call("GET", KEYS[1]) == ARGV[1] then
     return redis.call("DEL", KEYS[1])
 else
     return 0
-end
+end
\ No newline at end of file
diff --git a/core/stores/redis/lockscript.lua b/core/stores/redis/lockscript.lua
index 0fd75838..11a1fe35 100644
--- a/core/stores/redis/lockscript.lua
+++ b/core/stores/redis/lockscript.lua
@@ -3,4 +3,4 @@ if redis.call("GET", KEYS[1]) == ARGV[1] then
     return "OK"
 else
     return redis.call("SET", KEYS[1], ARGV[1], "NX", "PX", ARGV[2])
-end
+end
\ No newline at end of file
diff --git a/core/stores/redis/redislock.go b/core/stores/redis/redislock.go
index 28b704b8..4677dd1b 100644
--- a/core/stores/redis/redislock.go
+++ b/core/stores/redis/redislock.go
@@ -22,14 +22,12 @@ const (
 
 var (
 	//go:embed lockscript.lua
-	lockScript string
-
-	scriptLock = NewScript(lockScript)
+	lockLuaScript string
+	lockScript    = NewScript(lockLuaScript)
 
 	//go:embed delscript.lua
-	delScript string
-
-	scriptDel = NewScript(delScript)
+	delLuaScript string
+	delScript    = NewScript(delLuaScript)
 )
 
 // A RedisLock is a redis lock.
@@ -61,7 +59,7 @@ func (rl *RedisLock) Acquire() (bool, error) {
 // AcquireCtx acquires the lock with the given ctx.
 func (rl *RedisLock) AcquireCtx(ctx context.Context) (bool, error) {
 	seconds := atomic.LoadUint32(&rl.seconds)
-	resp, err := rl.store.ScriptRunCtx(ctx, scriptLock, []string{rl.key}, []string{
+	resp, err := rl.store.ScriptRunCtx(ctx, lockScript, []string{rl.key}, []string{
 		rl.id, strconv.Itoa(int(seconds)*millisPerSecond + tolerance),
 	})
 	if errors.Is(err, red.Nil) {
@@ -89,7 +87,7 @@ func (rl *RedisLock) Release() (bool, error) {
 
 // ReleaseCtx releases the lock with the given ctx.
 func (rl *RedisLock) ReleaseCtx(ctx context.Context) (bool, error) {
-	resp, err := rl.store.ScriptRunCtx(ctx, scriptDel, []string{rl.key}, []string{rl.id})
+	resp, err := rl.store.ScriptRunCtx(ctx, delScript, []string{rl.key}, []string{rl.id})
 	if err != nil {
 		return false, err
 	}


Test patch:
diff --git a/core/bloom/testscript.lua b/core/bloom/testscript.lua
index 2eda5784..a518ef49 100644
--- a/core/bloom/testscript.lua
+++ b/core/bloom/testscript.lua
@@ -3,4 +3,4 @@ for _, offset in ipairs(ARGV) do
         return false
     end
 end
-return true
+return true
\ No newline at end of file