newconf loads KEY_VALUE_URL

This commit is contained in:
Bel LaPointe
2026-02-03 17:11:34 -07:00
parent bb2c87dbd3
commit 7033e9f29c
4 changed files with 31 additions and 0 deletions

View File

@@ -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

View File

@@ -10,6 +10,7 @@ func Main(ctx context.Context) error {
return err
}
defer config.db.Close()
defer config.keyValue.Close()
if err := listen(ctx, config); err != nil && ctx.Err() == nil {
return err