66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/sethvargo/go-envconfig"
|
|
)
|
|
|
|
type Cfg struct {
|
|
FileSystem *WebdavConfig `env:", prefix=FILESYSTEM_"`
|
|
Cache *ValkeyConfig `env:", prefix=CACHE_"`
|
|
}
|
|
|
|
type WebdavConfig struct {
|
|
URL string `env:"URL"`
|
|
User string `env:"USERNAME"`
|
|
Password string `env:"PASSWORD"`
|
|
}
|
|
|
|
type ValkeyConfig struct {
|
|
ClientName string `env:"CLIENTNAME"`
|
|
Username string `env:"USERNAME"`
|
|
Password string `env:"PASSWORD"`
|
|
|
|
// InitAddress point to valkey nodes.
|
|
// Valkey will connect to them one by one and issue a CLUSTER SLOT command to initialize the cluster client until success.
|
|
// If len(InitAddress) == 1 and the address is not running in cluster mode, valkey will fall back to the single client mode.
|
|
// If ClientOption.Sentinel.MasterSet is set, then InitAddress will be used to connect sentinels
|
|
// You can bypass this behavior by using ClientOption.ForceSingleClient.
|
|
InitAddress []string `env:"ADDRESS"`
|
|
}
|
|
|
|
func Read(ctx context.Context) (cfg Cfg, err error) {
|
|
// ex, err := os.Executable()
|
|
// if err != nil {
|
|
// panic(err)
|
|
// }
|
|
// slog.Debug("loading .env", "pwd", filepath.Dir(ex))
|
|
// err = godotenv.Load(".")
|
|
// if err != nil {
|
|
// return
|
|
// }
|
|
//
|
|
slog.Info("adsf", "test", os.Getenv("TEST"))
|
|
|
|
err = envconfig.ProcessWith(ctx, &envconfig.Config{
|
|
Target: &cfg,
|
|
|
|
// All fields will use a ";" delimiter and "@" separator, unless locally
|
|
// overridden.
|
|
DefaultDelimiter: ";",
|
|
DefaultSeparator: "@",
|
|
|
|
Lookuper: envconfig.MultiLookuper(secretLookuper(), envconfig.OsLookuper()),
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
slog.Info("ca", "cacjhe", cfg.Cache)
|
|
|
|
return
|
|
}
|