newconf loads KEY_VALUE_URL
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
valkey "github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -11,6 +13,8 @@ type Config struct {
|
||||
ConnectionDriver string `json:"CONNECTION_DRIVER"`
|
||||
ConnectionString string `json:"CONNECTION_STRING"`
|
||||
db DB
|
||||
KeyValueURL string `json:"KEY_VALUE_URL"`
|
||||
keyValue *valkey.Client
|
||||
}
|
||||
|
||||
func NewConfig(ctx context.Context) (Config, error) {
|
||||
@@ -19,8 +23,20 @@ func NewConfig(ctx context.Context) (Config, error) {
|
||||
return config, err
|
||||
}
|
||||
|
||||
opt, err := valkey.ParseURL(config.KeyValueURL)
|
||||
if err != nil {
|
||||
return config, err
|
||||
}
|
||||
client := valkey.NewClient(opt)
|
||||
if err := client.Ping(ctx).Err(); err != nil {
|
||||
client.Close()
|
||||
return config, err
|
||||
}
|
||||
config.keyValue = client
|
||||
|
||||
db, err := NewDB(ctx, config.ConnectionDriver, config.ConnectionString)
|
||||
if err != nil {
|
||||
client.Close()
|
||||
return config, err
|
||||
}
|
||||
config.db = db
|
||||
@@ -33,6 +49,7 @@ func newConfig() (Config, error) {
|
||||
Listen: ":10000",
|
||||
ConnectionDriver: "sqlite",
|
||||
ConnectionString: "/tmp/red-apter.db",
|
||||
KeyValueURL: "redis://localhost:6379",
|
||||
}
|
||||
b, _ := json.Marshal(config)
|
||||
var m map[string]any
|
||||
|
||||
Reference in New Issue
Block a user