portal/config/config.go

39 lines
716 B
Go
Raw Normal View History

package config
import (
"errors"
"fmt"
"github.com/spf13/viper"
"go.uber.org/zap"
)
var (
ConfigFilePaths = []string{
"/etc/lumeweb/portal/",
"$HOME/.lumeweb/portal/",
".",
}
)
func Init(logger *zap.Logger) {
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{}) {
// Config file not found, this is not an error.
fmt.Println("Config file not found, using default settings.")
} else {
logger.Fatal("Fatal error config file", zap.Error(err))
}
}
}