Skip to content

Commit 42d6ad6

Browse files
sosyzLinkinStars
authored andcommitted
fix(plugin): rename 'close' to avoid builtin collision
1 parent 9f8cab5 commit 42d6ad6

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

plugin/kv_storage.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ type KVOperator struct {
4848
pluginSlugName string
4949
}
5050

51-
func (kv *KVOperator) getSession(ctx context.Context) (session *xorm.Session, close func()) {
52-
if kv.session != nil {
53-
session = kv.session
54-
} else {
51+
func (kv *KVOperator) getSession(ctx context.Context) (*xorm.Session, func()) {
52+
session := kv.session
53+
cleanup := func() {}
54+
if session == nil {
5555
session = kv.data.DB.NewSession().Context(ctx)
56-
close = func() {
56+
cleanup = func() {
5757
if session != nil {
5858
session.Close()
5959
}
6060
}
6161
}
62-
return
62+
return session, cleanup
6363
}
6464

6565
func (kv *KVOperator) getCacheTTL() time.Duration {
@@ -89,8 +89,8 @@ func (kv *KVOperator) Get(ctx context.Context, group, key string) (string, error
8989

9090
// query
9191
data := entity.PluginKVStorage{}
92-
query, close := kv.getSession(ctx)
93-
defer close()
92+
query, cleanup := kv.getSession(ctx)
93+
defer cleanup()
9494

9595
query.Where(builder.Eq{
9696
"plugin_slug_name": kv.pluginSlugName,
@@ -118,10 +118,8 @@ func (kv *KVOperator) Set(ctx context.Context, group, key, value string) error {
118118
return ErrKVKeyEmpty
119119
}
120120

121-
query, close := kv.getSession(ctx)
122-
if close != nil {
123-
defer close()
124-
}
121+
query, cleanup := kv.getSession(ctx)
122+
defer cleanup()
125123

126124
data := &entity.PluginKVStorage{
127125
PluginSlugName: kv.pluginSlugName,
@@ -157,8 +155,8 @@ func (kv *KVOperator) Del(ctx context.Context, group, key string) error {
157155

158156
kv.cleanCache(ctx, group, key)
159157

160-
session, close := kv.getSession(ctx)
161-
defer close()
158+
session, cleanup := kv.getSession(ctx)
159+
defer cleanup()
162160

163161
session.Where(builder.Eq{
164162
"plugin_slug_name": kv.pluginSlugName,
@@ -214,8 +212,8 @@ func (kv *KVOperator) GetByGroup(ctx context.Context, group string, page, pageSi
214212
}
215213
}
216214

217-
query, close := kv.getSession(ctx)
218-
defer close()
215+
query, cleanup := kv.getSession(ctx)
216+
defer cleanup()
219217

220218
var items []entity.PluginKVStorage
221219
err := query.Where(builder.Eq{"plugin_slug_name": kv.pluginSlugName, "`group`": group}).

0 commit comments

Comments
 (0)