diff --git a/config/conf.json b/config/conf.json index f1b5b1f..b68d93a 100644 --- a/config/conf.json +++ b/config/conf.json @@ -11,7 +11,8 @@ "host": "127.0.0.1", "port": "6379", "max_conns": 50, - "timeout_ms": 5000 + "timeout_ms": 5000, + "password": "the_valkey_password" }, "temp": "value" } \ No newline at end of file diff --git a/config/config.go b/config/config.go index 1561e79..79d212e 100644 --- a/config/config.go +++ b/config/config.go @@ -21,6 +21,7 @@ type Config struct { Port string `json:"port"` MaxConns int `json:"max_conns"` TimeoutMs int `json:"timeout_ms"` + Password string `json:"password"` // Add this line } `json:"valkey"` Temp string `json:"temp"` } diff --git a/config/valkey.go b/config/valkey.go index 343e2b6..778bf6d 100644 --- a/config/valkey.go +++ b/config/valkey.go @@ -17,6 +17,7 @@ type ValkeyConfig struct { Port string `json:"port"` MaxConns int `json:"max_conns"` TimeoutMs int `json:"timeout_ms"` + Password string `json:"password"` // Add this line } func LoadValkeyConfig(file string) (ValkeyConfig, error) { @@ -48,21 +49,27 @@ func LoadValkeyConfig(file string) (ValkeyConfig, error) { config.TimeoutMs = val } } + if password := os.Getenv("VALKEY_PASSWORD"); password != "" { + config.Password = password + } return config, nil } func ConnectToValkey(configPath string) (valkey.Client, error) { - fmt.Println("Loading Valkey configuration...") - valkeyConfig, err := LoadValkeyConfig(configPath) + fmt.Println("Loading configuration...") + config, err := LoadConfig(configPath) if err != nil { - return nil, fmt.Errorf("failed to load Valkey config: %v", err) + return nil, fmt.Errorf("failed to load config: %v", err) } - fmt.Println("Valkey configuration loaded successfully!") + fmt.Println("Configuration loaded successfully!") + + valkeyConfig := config.Valkey // Setup Valkey client options options := valkey.ClientOption{ InitAddress: []string{fmt.Sprintf("%s:%s", valkeyConfig.Host, valkeyConfig.Port)}, + Password: valkeyConfig.Password, // Additional options can be added here if required }