Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(plugin): rename 'close' to avoid builtin collision

Sonuid90810afd7e0
diff --git a/plugin/kv_storage.go b/plugin/kv_storage.go
index a3ab46d0..0ec3d640 100644
--- a/plugin/kv_storage.go
+++ b/plugin/kv_storage.go
@@ -48,18 +48,18 @@ type KVOperator struct {
pluginSlugName string
}
-func (kv *KVOperator) getSession(ctx context.Context) (session *xorm.Session, close func()) {
- if kv.session != nil {
- session = kv.session
- } else {
+func (kv *KVOperator) getSession(ctx context.Context) (*xorm.Session, func()) {
+ session := kv.session
+ cleanup := func() {}
+ if session == nil {
session = kv.data.DB.NewSession().Context(ctx)
- close = func() {
+ cleanup = func() {
if session != nil {
session.Close()
}
}
}
- return
+ return session, cleanup
}
func (kv *KVOperator) getCacheTTL() time.Duration {
@@ -89,8 +89,8 @@ func (kv *KVOperator) Get(ctx context.Context, group, key string) (string, error
// query
data := entity.PluginKVStorage{}
- query, close := kv.getSession(ctx)
- defer close()
+ query, cleanup := kv.getSession(ctx)
+ defer cleanup()
query.Where(builder.Eq{
"plugin_slug_name": kv.pluginSlugName,
@@ -118,10 +118,8 @@ func (kv *KVOperator) Set(ctx context.Context, group, key, value string) error {
return ErrKVKeyEmpty
}
- query, close := kv.getSession(ctx)
- if close != nil {
- defer close()
- }
+ query, cleanup := kv.getSession(ctx)
+ defer cleanup()
data := &entity.PluginKVStorage{
PluginSlugName: kv.pluginSlugName,
@@ -157,8 +155,8 @@ func (kv *KVOperator) Del(ctx context.Context, group, key string) error {
kv.cleanCache(ctx, group, key)
- session, close := kv.getSession(ctx)
- defer close()
+ session, cleanup := kv.getSession(ctx)
+ defer cleanup()
session.Where(builder.Eq{
"plugin_slug_name": kv.pluginSlugName,
@@ -214,8 +212,8 @@ func (kv *KVOperator) GetByGroup(ctx context.Context, group string, page, pageSi
}
}
- query, close := kv.getSession(ctx)
- defer close()
+ query, cleanup := kv.getSession(ctx)
+ defer cleanup()
var items []entity.PluginKVStorage
err := query.Where(builder.Eq{"plugin_slug_name": kv.pluginSlugName, "`group`": group}).