Skip to content

Commit

Permalink
fix: Use Vipers config finder
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Jul 12, 2023
1 parent ef86ad3 commit 1c75a1b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/gate/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,21 @@ func initViper(c *cli.Context, configFile string) (*viper.Viper, error) {

// FixedReadInConfig is a workaround for https://github.com/minekube/gate/issues/218#issuecomment-1632800775
func FixedReadInConfig[T any](v *viper.Viper, configFile string, defaultConfig *T) error {
if configFile == "" || defaultConfig == nil {
if defaultConfig == nil {
return v.ReadInConfig()
}

if configFile == "" {
// Try to find config file using Viper's config finder logic
if err := v.ReadInConfig(); err != nil {
return err
}
configFile = v.ConfigFileUsed()
if configFile == "" {
return nil // no config file found
}
}

var (
unmarshal func([]byte, any) error
marshal func(any) ([]byte, error)
Expand Down

0 comments on commit 1c75a1b

Please sign in to comment.