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

44 lines
877 B
Go
Raw Normal View History

2019-05-26 19:32:16 +00:00
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")
2019-05-27 21:46:09 +00:00
viper.SetDefault("DataService.Username", "haveachin")
viper.SetDefault("DataService.Password", "<changeme>")
viper.SetDefault("DataService.Database", "scoreboard")
2019-05-26 19:32:16 +00:00
}