From a008d360b4cda5deff8bfcce10a518c98ca717d8 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Sun, 30 Jun 2024 11:20:51 +0100 Subject: [PATCH] Create type alias for redis.UniversalOptions Signed-off-by: Milos Gajdos --- configuration/configuration.go | 20 ++++++++++++-------- configuration/configuration_test.go | 8 ++------ registry/handlers/app.go | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 253c0615c..783cd2ea9 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -653,19 +653,23 @@ func Parse(rd io.Reader) (*Configuration, error) { return config, nil } +type RedisOptions = redis.UniversalOptions + +type RedisTLSOptions struct { + Certificate string `yaml:"certificate,omitempty"` + Key string `yaml:"key,omitempty"` + ClientCAs []string `yaml:"clientcas,omitempty"` +} + type Redis struct { - redis.UniversalOptions `yaml:",inline"` - TLS struct { - Certificate string `yaml:"certificate,omitempty"` - Key string `yaml:"key,omitempty"` - ClientCAs []string `yaml:"clientcas,omitempty"` - } `yaml:"tls,omitempty"` + Options RedisOptions `yaml:",inline"` + TLS RedisTLSOptions `yaml:"tls,omitempty"` } func (c Redis) MarshalYAML() (interface{}, error) { fields := make(map[string]interface{}) - val := reflect.ValueOf(c.UniversalOptions) + val := reflect.ValueOf(c.Options) typ := val.Type() for i := 0; i < val.NumField(); i++ { @@ -695,7 +699,7 @@ func (c *Redis) UnmarshalYAML(unmarshal func(interface{}) error) error { return err } - val := reflect.ValueOf(&c.UniversalOptions).Elem() + val := reflect.ValueOf(&c.Options).Elem() typ := val.Type() for i := 0; i < typ.NumField(); i++ { diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 73085367f..ba538802c 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -132,7 +132,7 @@ var configStruct = Configuration{ }, }, Redis: Redis{ - UniversalOptions: redis.UniversalOptions{ + Options: redis.UniversalOptions{ Addrs: []string{"localhost:6379"}, Username: "alice", Password: "123456", @@ -144,11 +144,7 @@ var configStruct = Configuration{ ReadTimeout: time.Millisecond * 10, WriteTimeout: time.Millisecond * 10, }, - TLS: struct { - Certificate string `yaml:"certificate,omitempty"` - Key string `yaml:"key,omitempty"` - ClientCAs []string `yaml:"clientcas,omitempty"` - }{ + TLS: RedisTLSOptions{ Certificate: "/foo/cert.crt", Key: "/foo/key.pem", ClientCAs: []string{"/path/to/ca.pem"}, diff --git a/registry/handlers/app.go b/registry/handlers/app.go index 414ea8db0..02a8847ec 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -489,7 +489,7 @@ func (app *App) configureEvents(configuration *configuration.Configuration) { } func (app *App) configureRedis(cfg *configuration.Configuration) { - if len(cfg.Redis.Addrs) == 0 { + if len(cfg.Redis.Options.Addrs) == 0 { dcontext.GetLogger(app).Infof("redis not configured") return } @@ -520,10 +520,10 @@ func (app *App) configureRedis(cfg *configuration.Configuration) { tlsConf.ClientAuth = tls.RequireAndVerifyClientCert tlsConf.ClientCAs = pool } - cfg.Redis.UniversalOptions.TLSConfig = tlsConf + cfg.Redis.Options.TLSConfig = tlsConf } - app.redis = app.createPool(cfg.Redis.UniversalOptions) + app.redis = app.createPool(cfg.Redis.Options) // Enable metrics instrumentation. if err := redisotel.InstrumentMetrics(app.redis); err != nil {