package config import ( "context" "github.com/sethvargo/go-envconfig" ) type Cfg struct { FileSystem *WebdavConfig `env:", prefix=FILESYSTEM_"` Cache *ValkeyConfig `env:", prefix=CACHE_"` Image *ImageConfig `env:", prefix=IMAGE_"` } 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"` } type ImageConfig struct { Concurency int64 `env:"CONCURENCY"` Quality int `env:"QUALITY"` } func Read(ctx context.Context) (cfg Cfg, err error) { cfg = Default() 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 } return }