Skip to content

Commit

Permalink
Don't set default port in pkg/redis
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Oct 9, 2023
1 parent 1839eea commit 06b2247
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type Config struct {
Retention RetentionConfig `yaml:"retention"`
}

func (c *Config) Init() {
c.Redis.Port = 6380
}

// Validate checks constraints in the supplied configuration and returns an error if they are violated.
func (c *Config) Validate() error {
if err := c.Database.Validate(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ redis:
input: miniConf,
output: func() *Config {
c := &Config{}
c.Init()
_ = defaults.Set(c)

c.Database.Host = "192.0.2.1"
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"os"
)

type Initer interface {
Init()
}

type Validator interface {
Validate() error
}
Expand All @@ -28,6 +32,10 @@ func FromYAMLFile[T any, P interface {

c := P(new(T))

if initer, ok := any(c).(Initer); ok {
initer.Init()
}

if err := defaults.Set(c); err != nil {
return nil, errors.Wrap(err, "can't set config defaults")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func NewClientFromConfig(c *Config, logger *logging.Logger) (*Client, error) {
options.Network = "unix"
options.Addr = c.Host
} else {
port := c.Port
if port == 0 {
port = 6379
}
options.Network = "tcp"
options.Addr = utils.JoinHostPort(c.Host, c.Port)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// Config defines Config client configuration.
type Config struct {
Host string `yaml:"host"`
Port int `yaml:"port" default:"6380"`
Port int `yaml:"port"`
Password string `yaml:"password"`
TlsOptions config.TLS `yaml:",inline"`
Options Options `yaml:"options"`
Expand Down

0 comments on commit 06b2247

Please sign in to comment.