Allow MYLOG_CONFIG_PATH to override the config path

This commit is contained in:
Dan Jones 2026-03-09 16:48:58 -05:00
commit edf10de879
4 changed files with 18 additions and 20 deletions

View file

@ -32,7 +32,7 @@ func AddToContext(ctx context.Context, v *viper.Viper) context.Context {
return context.WithValue(ctx, viperKey, v)
}
func New(ctx context.Context) (context.Context, *viper.Viper, error) {
func New(ctx context.Context, path string) (context.Context, *viper.Viper, error) {
v := viper.New()
v.SetConfigType("toml")
@ -40,12 +40,16 @@ func New(ctx context.Context) (context.Context, *viper.Viper, error) {
return ctx, nil, err
}
v.SetConfigFile(DefaultPath())
if path == "" {
path = DefaultPath()
}
v.SetConfigFile(path)
v.SetEnvPrefix("MYLOG")
v.AutomaticEnv()
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
if err := v.ReadInConfig(); err != nil {
if err := v.MergeInConfig(); err != nil {
return ctx, nil, err
}