chore: change interface{} to any (#2818)

* chore: change interface{} to any

* chore: update goctl version to 1.5.0

* chore: update goctl deps
This commit is contained in:
Kevin Wan
2023-01-24 16:32:02 +08:00
committed by GitHub
parent 7e0ac77139
commit ae87114282
221 changed files with 1910 additions and 2207 deletions

View File

@@ -89,12 +89,12 @@ func (c cacheNode) DelCtx(ctx context.Context, keys ...string) error {
}
// Get gets the cache with key and fills into v.
func (c cacheNode) Get(key string, val interface{}) error {
func (c cacheNode) Get(key string, val any) error {
return c.GetCtx(context.Background(), key, val)
}
// GetCtx gets the cache with key and fills into v.
func (c cacheNode) GetCtx(ctx context.Context, key string, val interface{}) error {
func (c cacheNode) GetCtx(ctx context.Context, key string, val any) error {
err := c.doGetCache(ctx, key, val)
if err == errPlaceholder {
return c.errNotFound
@@ -109,22 +109,22 @@ func (c cacheNode) IsNotFound(err error) bool {
}
// Set sets the cache with key and v, using c.expiry.
func (c cacheNode) Set(key string, val interface{}) error {
func (c cacheNode) Set(key string, val any) error {
return c.SetCtx(context.Background(), key, val)
}
// SetCtx sets the cache with key and v, using c.expiry.
func (c cacheNode) SetCtx(ctx context.Context, key string, val interface{}) error {
func (c cacheNode) SetCtx(ctx context.Context, key string, val any) error {
return c.SetWithExpireCtx(ctx, key, val, c.aroundDuration(c.expiry))
}
// SetWithExpire sets the cache with key and v, using given expire.
func (c cacheNode) SetWithExpire(key string, val interface{}, expire time.Duration) error {
func (c cacheNode) SetWithExpire(key string, val any, expire time.Duration) error {
return c.SetWithExpireCtx(context.Background(), key, val, expire)
}
// SetWithExpireCtx sets the cache with key and v, using given expire.
func (c cacheNode) SetWithExpireCtx(ctx context.Context, key string, val interface{},
func (c cacheNode) SetWithExpireCtx(ctx context.Context, key string, val any,
expire time.Duration) error {
data, err := jsonx.Marshal(val)
if err != nil {
@@ -141,34 +141,34 @@ func (c cacheNode) String() string {
// Take takes the result from cache first, if not found,
// query from DB and set cache using c.expiry, then return the result.
func (c cacheNode) Take(val interface{}, key string, query func(val interface{}) error) error {
func (c cacheNode) Take(val any, key string, query func(val any) error) error {
return c.TakeCtx(context.Background(), val, key, query)
}
// TakeCtx takes the result from cache first, if not found,
// query from DB and set cache using c.expiry, then return the result.
func (c cacheNode) TakeCtx(ctx context.Context, val interface{}, key string,
query func(val interface{}) error) error {
return c.doTake(ctx, val, key, query, func(v interface{}) error {
func (c cacheNode) TakeCtx(ctx context.Context, val any, key string,
query func(val any) error) error {
return c.doTake(ctx, val, key, query, func(v any) error {
return c.SetCtx(ctx, key, v)
})
}
// TakeWithExpire takes the result from cache first, if not found,
// query from DB and set cache using given expire, then return the result.
func (c cacheNode) TakeWithExpire(val interface{}, key string, query func(val interface{},
func (c cacheNode) TakeWithExpire(val any, key string, query func(val any,
expire time.Duration) error) error {
return c.TakeWithExpireCtx(context.Background(), val, key, query)
}
// TakeWithExpireCtx takes the result from cache first, if not found,
// query from DB and set cache using given expire, then return the result.
func (c cacheNode) TakeWithExpireCtx(ctx context.Context, val interface{}, key string,
query func(val interface{}, expire time.Duration) error) error {
func (c cacheNode) TakeWithExpireCtx(ctx context.Context, val any, key string,
query func(val any, expire time.Duration) error) error {
expire := c.aroundDuration(c.expiry)
return c.doTake(ctx, val, key, func(v interface{}) error {
return c.doTake(ctx, val, key, func(v any) error {
return query(v, expire)
}, func(v interface{}) error {
}, func(v any) error {
return c.SetWithExpireCtx(ctx, key, v, expire)
})
}
@@ -184,7 +184,7 @@ func (c cacheNode) asyncRetryDelCache(keys ...string) {
}, keys...)
}
func (c cacheNode) doGetCache(ctx context.Context, key string, v interface{}) error {
func (c cacheNode) doGetCache(ctx context.Context, key string, v any) error {
c.stat.IncrementTotal()
data, err := c.rds.GetCtx(ctx, key)
if err != nil {
@@ -205,10 +205,10 @@ func (c cacheNode) doGetCache(ctx context.Context, key string, v interface{}) er
return c.processCache(ctx, key, data, v)
}
func (c cacheNode) doTake(ctx context.Context, v interface{}, key string,
query func(v interface{}) error, cacheVal func(v interface{}) error) error {
func (c cacheNode) doTake(ctx context.Context, v any, key string,
query func(v any) error, cacheVal func(v any) error) error {
logger := logx.WithContext(ctx)
val, fresh, err := c.barrier.DoEx(key, func() (interface{}, error) {
val, fresh, err := c.barrier.DoEx(key, func() (any, error) {
if err := c.doGetCache(ctx, key, v); err != nil {
if err == errPlaceholder {
return nil, c.errNotFound
@@ -255,7 +255,7 @@ func (c cacheNode) doTake(ctx context.Context, v interface{}, key string,
return jsonx.Unmarshal(val.([]byte), v)
}
func (c cacheNode) processCache(ctx context.Context, key, data string, v interface{}) error {
func (c cacheNode) processCache(ctx context.Context, key, data string, v any) error {
err := jsonx.Unmarshal([]byte(data), v)
if err == nil {
return nil