39 lines
634 B
Go
39 lines
634 B
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/spf13/viper"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var (
|
|
ConfigFilePaths = []string{
|
|
"/etc/lumeweb/portal/",
|
|
"$HOME/.lumeweb/portal/",
|
|
".",
|
|
}
|
|
)
|
|
|
|
func Init(logger *zap.Logger) error {
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("yaml")
|
|
|
|
for _, path := range ConfigFilePaths {
|
|
viper.AddConfigPath(path)
|
|
}
|
|
|
|
viper.SetEnvPrefix("LUME_WEB_PORTAL")
|
|
viper.AutomaticEnv()
|
|
|
|
err := viper.ReadInConfig()
|
|
if err != nil {
|
|
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
|
|
logger.Info("Config file not found, using default settings.")
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|