This repository has been archived on 2019-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
scoreboard/config/config.go

40 lines
707 B
Go

package config
import (
"github.com/spf13/viper"
)
type Config struct {
Port uint16
DataService DataService
}
type DataService struct {
IP string
Port uint16
Username string
Password string
Database string
}
func New() (*Config, error) {
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.SetConfigName("config")
if err := viper.ReadInConfig(); err != nil {
return nil, err
}
setDefaults()
var config Config
err := viper.Unmarshal(&config)
return &config, err
}
func setDefaults() {
viper.SetDefault("Port", "8080")
viper.SetDefault("DataService.IP", "127.0.0.1")
viper.SetDefault("DataService.Port", "27017")
}