mirror of
https://github.com/project-zot/zot.git
synced 2026-06-18 21:48:04 +08:00
chore: update golangci-lint and fix all issues (#3575)
* chore: Update golangci-lint Signed-off-by: Lars Francke <git@lars-francke.de> * chore: fix all golangci-lint issues - Remove deprecated `// +build` tags - Fix godoclint, modernize, wsl_v5, govet, lll, gci, noctx issues - Update linter configuration - Modernize code to use Go 1.22+ features (for range N, slices.Contains, etc.) - Update make check lint the privileged tests Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com> --------- Signed-off-by: Lars Francke <git@lars-francke.de> Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com> Co-authored-by: Lars Francke <git@lars-francke.de>
This commit is contained in:
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"maps"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -34,8 +35,8 @@ type StorageConfig struct {
|
||||
GCDelay time.Duration // applied for blobs
|
||||
GCInterval time.Duration
|
||||
Retention ImageRetention
|
||||
StorageDriver map[string]interface{} `mapstructure:",omitempty"`
|
||||
CacheDriver map[string]interface{} `mapstructure:",omitempty"`
|
||||
StorageDriver map[string]any `mapstructure:",omitempty"`
|
||||
CacheDriver map[string]any `mapstructure:",omitempty"`
|
||||
|
||||
// GCMaxSchedulerDelay is the maximum random delay for GC task scheduling
|
||||
// This field is not configurable by the end user
|
||||
@@ -210,7 +211,7 @@ type SchedulerConfig struct {
|
||||
NumWorkers int
|
||||
}
|
||||
|
||||
// contains the scale-out configuration which is identical for all zot replicas.
|
||||
// ClusterConfig contains the scale-out configuration which is identical for all zot replicas.
|
||||
type ClusterConfig struct {
|
||||
// contains the "host:port" of all the zot instances participating
|
||||
// in the cluster.
|
||||
@@ -305,7 +306,8 @@ type LogConfig struct {
|
||||
|
||||
type GlobalStorageConfig struct {
|
||||
StorageConfig `mapstructure:",squash"`
|
||||
SubPaths map[string]StorageConfig
|
||||
|
||||
SubPaths map[string]StorageConfig
|
||||
}
|
||||
|
||||
type AccessControlConfig struct {
|
||||
@@ -377,9 +379,7 @@ func (config *AccessControlConfig) GetRepositories() Repositories {
|
||||
|
||||
// Return a copy to avoid race conditions
|
||||
reposCopy := make(Repositories)
|
||||
for k, v := range config.Repositories {
|
||||
reposCopy[k] = v
|
||||
}
|
||||
maps.Copy(reposCopy, config.Repositories)
|
||||
|
||||
return reposCopy
|
||||
}
|
||||
@@ -410,9 +410,7 @@ func (config *AccessControlConfig) GetGroups() Groups {
|
||||
|
||||
// Return a copy to avoid race conditions
|
||||
groupsCopy := make(Groups)
|
||||
for k, v := range config.Groups {
|
||||
groupsCopy[k] = v
|
||||
}
|
||||
maps.Copy(groupsCopy, config.Groups)
|
||||
|
||||
return groupsCopy
|
||||
}
|
||||
@@ -1101,7 +1099,7 @@ func SameFile(str1, str2 string) (bool, error) {
|
||||
}
|
||||
|
||||
// DeepCopy performs a deep copy of src into dst using JSON marshaling/unmarshaling.
|
||||
func DeepCopy(src, dst interface{}) error {
|
||||
func DeepCopy(src, dst any) error {
|
||||
bytes, err := json.Marshal(src)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build needprivileges
|
||||
// +build needprivileges
|
||||
|
||||
package config_test
|
||||
|
||||
|
||||
@@ -1265,10 +1265,10 @@ func TestConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
StorageDriver: map[string]interface{}{
|
||||
StorageDriver: map[string]any{
|
||||
"type": "filesystem",
|
||||
},
|
||||
CacheDriver: map[string]interface{}{
|
||||
CacheDriver: map[string]any{
|
||||
"type": "redis",
|
||||
},
|
||||
},
|
||||
@@ -1282,7 +1282,7 @@ func TestConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
StorageDriver: map[string]interface{}{
|
||||
StorageDriver: map[string]any{
|
||||
"type": "s3",
|
||||
},
|
||||
},
|
||||
|
||||
@@ -20,11 +20,11 @@ type RedisLogger struct {
|
||||
Log log.Logger
|
||||
}
|
||||
|
||||
func (r RedisLogger) Printf(ctx context.Context, format string, v ...interface{}) {
|
||||
func (r RedisLogger) Printf(ctx context.Context, format string, v ...any) {
|
||||
r.Log.Debug().Msgf(format, v...)
|
||||
}
|
||||
|
||||
func GetRedisClient(redisConfig map[string]interface{}, log log.Logger) (redis.UniversalClient, error) {
|
||||
func GetRedisClient(redisConfig map[string]any, log log.Logger) (redis.UniversalClient, error) {
|
||||
once.Do(func() { redis.SetLogger(RedisLogger{log}) }) // call redis.SetLogger only once
|
||||
|
||||
// go-redis supports connecting via the redis uri specification (more convenient than parameter parsing)
|
||||
@@ -59,11 +59,11 @@ func GetRedisClient(redisConfig map[string]interface{}, log log.Logger) (redis.U
|
||||
return redis.NewUniversalClient(opts), nil
|
||||
}
|
||||
|
||||
func ParseRedisUniversalOptions(redisConfig map[string]interface{}, //nolint: gocyclo
|
||||
func ParseRedisUniversalOptions(redisConfig map[string]any, //nolint: gocyclo
|
||||
log log.Logger,
|
||||
) *redis.UniversalOptions {
|
||||
opts := redis.UniversalOptions{}
|
||||
sanitizedConfig := map[string]interface{}{}
|
||||
sanitizedConfig := map[string]any{}
|
||||
|
||||
for key, val := range redisConfig {
|
||||
if key == "password" || key == "sentinel_password" {
|
||||
@@ -206,7 +206,7 @@ func ParseRedisUniversalOptions(redisConfig map[string]interface{}, //nolint: go
|
||||
return &opts
|
||||
}
|
||||
|
||||
func logCastWarning(key string, value interface{}, hideValue bool, log log.Logger) {
|
||||
func logCastWarning(key string, value any, hideValue bool, log log.Logger) {
|
||||
if hideValue {
|
||||
log.Warn().Str("key", key).Msg("failed to cast parameter to intended type")
|
||||
} else {
|
||||
@@ -214,7 +214,7 @@ func logCastWarning(key string, value interface{}, hideValue bool, log log.Logge
|
||||
}
|
||||
}
|
||||
|
||||
func getBool(dict map[string]interface{}, key string, log log.Logger) (bool, bool) {
|
||||
func getBool(dict map[string]any, key string, log log.Logger) (bool, bool) {
|
||||
value, ok := dict[key]
|
||||
if !ok {
|
||||
return false, false
|
||||
@@ -230,7 +230,7 @@ func getBool(dict map[string]interface{}, key string, log log.Logger) (bool, boo
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func getInt(dict map[string]interface{}, key string, log log.Logger) (int, bool) {
|
||||
func getInt(dict map[string]any, key string, log log.Logger) (int, bool) {
|
||||
value, ok := dict[key]
|
||||
if !ok {
|
||||
return 0, false
|
||||
@@ -246,7 +246,7 @@ func getInt(dict map[string]interface{}, key string, log log.Logger) (int, bool)
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func GetString(dict map[string]interface{}, key string, hideValue bool, log log.Logger) (string, bool) {
|
||||
func GetString(dict map[string]any, key string, hideValue bool, log log.Logger) (string, bool) {
|
||||
value, ok := dict[key]
|
||||
if !ok {
|
||||
return "", false
|
||||
@@ -262,7 +262,7 @@ func GetString(dict map[string]interface{}, key string, hideValue bool, log log.
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func getStringSlice(dict map[string]interface{}, key string, log log.Logger) ([]string, bool) {
|
||||
func getStringSlice(dict map[string]any, key string, log log.Logger) ([]string, bool) {
|
||||
value, ok := dict[key]
|
||||
if !ok {
|
||||
return []string{}, false
|
||||
@@ -278,7 +278,7 @@ func getStringSlice(dict map[string]interface{}, key string, log log.Logger) ([]
|
||||
return ret, true
|
||||
}
|
||||
|
||||
func getDuration(dict map[string]interface{}, key string, log log.Logger) (time.Duration, bool) {
|
||||
func getDuration(dict map[string]any, key string, log log.Logger) (time.Duration, bool) {
|
||||
value, ok := dict[key]
|
||||
if !ok {
|
||||
return 0, false
|
||||
|
||||
@@ -42,38 +42,38 @@ func TestRedisOptions(t *testing.T) {
|
||||
|
||||
Convey("Test redis url parsing", func() {
|
||||
// Errors
|
||||
config := map[string]interface{}{"url": false}
|
||||
config := map[string]any{"url": false}
|
||||
|
||||
clientIntf, err := rediscfg.GetRedisClient(config, log)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(clientIntf, ShouldBeNil)
|
||||
|
||||
config = map[string]interface{}{"url": ""}
|
||||
config = map[string]any{"url": ""}
|
||||
|
||||
clientIntf, err = rediscfg.GetRedisClient(config, log)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(clientIntf, ShouldBeNil)
|
||||
|
||||
config = map[string]interface{}{"url": "qwerty@localhost:6379/1?dial_timeout=5s"}
|
||||
config = map[string]any{"url": "qwerty@localhost:6379/1?dial_timeout=5s"}
|
||||
|
||||
clientIntf, err = rediscfg.GetRedisClient(config, log)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(clientIntf, ShouldBeNil)
|
||||
|
||||
config = map[string]interface{}{"url": "http://:qwerty@localhost:6379/1?dial_timeout=5s"}
|
||||
config = map[string]any{"url": "http://:qwerty@localhost:6379/1?dial_timeout=5s"}
|
||||
|
||||
clientIntf, err = rediscfg.GetRedisClient(config, log)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(clientIntf, ShouldBeNil)
|
||||
|
||||
config = map[string]interface{}{"url": "http://localhost:6379/1?addr=host2:6379&addr=host1:6379"}
|
||||
config = map[string]any{"url": "http://localhost:6379/1?addr=host2:6379&addr=host1:6379"}
|
||||
|
||||
clientIntf, err = rediscfg.GetRedisClient(config, log)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(clientIntf, ShouldBeNil)
|
||||
|
||||
// Success
|
||||
config = map[string]interface{}{"url": "redis://user:password@localhost:6379/1?dial_timeout=5s"}
|
||||
config = map[string]any{"url": "redis://user:password@localhost:6379/1?dial_timeout=5s"}
|
||||
|
||||
clientIntf, err = rediscfg.GetRedisClient(config, log)
|
||||
So(err, ShouldBeNil)
|
||||
@@ -82,7 +82,7 @@ func TestRedisOptions(t *testing.T) {
|
||||
_, ok := clientIntf.(*redis.Client)
|
||||
So(ok, ShouldBeTrue)
|
||||
|
||||
config = map[string]interface{}{"url": "redis://user:password@host1:6379?addr=host2:6379&addr=host1:6379"}
|
||||
config = map[string]any{"url": "redis://user:password@host1:6379?addr=host2:6379&addr=host1:6379"}
|
||||
|
||||
clientIntf, err = rediscfg.GetRedisClient(config, log)
|
||||
So(err, ShouldBeNil)
|
||||
@@ -93,7 +93,7 @@ func TestRedisOptions(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Test empty redis options from struct successfully", func() {
|
||||
config := map[string]interface{}{}
|
||||
config := map[string]any{}
|
||||
|
||||
// All attributes will have zero values
|
||||
options := rediscfg.ParseRedisUniversalOptions(config, log)
|
||||
@@ -139,7 +139,7 @@ func TestRedisOptions(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Test redis options from struct successfully", func() {
|
||||
config := map[string]interface{}{
|
||||
config := map[string]any{
|
||||
"addr": []string{
|
||||
"a.repo:26379",
|
||||
"b.repo:26379",
|
||||
@@ -221,7 +221,7 @@ func TestRedisOptions(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Test redis options from struct with warnings", func() {
|
||||
config := map[string]interface{}{
|
||||
config := map[string]any{
|
||||
"addr": map[string]int{},
|
||||
"db": "somestring",
|
||||
"master_name": map[string]int{},
|
||||
|
||||
Reference in New Issue
Block a user