sirius/cmd/apisirius/config.go
Anatoly Prohacky d596cab3fd config
2023-04-25 20:14:01 +10:00

38 lines
708 B
Go

package main
import (
"flag"
"github.com/spf13/viper"
"gitstore.ru/tolikproh/sirius/internal/model"
)
var (
configPath string
configFile string = "config"
)
func init() {
flag.StringVar(&configPath, "conf-path", "configs", "path to config file 'config.yml'")
flag.StringVar(&configFile, "conf-file", "config", "name file to config")
}
func initConfig() (*model.Config, error) {
cnf := model.NewConfig()
viper.SetConfigName(configFile)
viper.SetConfigType("yaml")
viper.AddConfigPath(configPath)
viper.AddConfigPath("./")
if err := viper.ReadInConfig(); err != nil {
return cnf, err
} else {
if err := viper.Unmarshal(&cnf); err != nil {
return cnf, err
}
}
return cnf, nil
}