diff options
| author | Max | 2018-02-05 02:54:46 +0100 |
|---|---|---|
| committer | Max | 2018-02-05 02:54:46 +0100 |
| commit | 91c901a764dbf2d600366ed1d8ee19c813d3047d (patch) | |
| tree | 20ac392dc96bf80d48b278f5027a4b44a257dfaf /config.go | |
| parent | 543ebae42be1b7385e476a4699a7f88e95a2d120 (diff) | |
| download | alkobote-91c901a764dbf2d600366ed1d8ee19c813d3047d.tar.gz | |
Adds some database code.
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -6,21 +6,26 @@ import ( ) type Config struct { + DBDriver string DBDBName string DBHost string DBPort int DBUser string DBPassword string DBOptions string + DBPath string // for sqlite } // Parses the configuration and sets the configuration struct. func (c *Config) parseConfig(configFile string) { + viper.SetDefault("DBDriver", "mysql") viper.SetDefault("DBDBName", "alkobote") viper.SetDefault("DBHost", "127.0.0.1") viper.SetDefault("DBPort", 3306) + viper.SetDefault("DBPath", "./alkobote.db") + // Name of the configuration file viper.SetConfigName("config") @@ -52,3 +57,15 @@ func (c *Config) parseConfig(configFile string) { c.setsConfig() } + +// Actually sets the config struct +func (c *Config) setsConfig() { + c.DBDriver = viper.GetString("DBDriver") + c.DBHost = viper.GetString("DBHost") + c.DBPort = viper.GetInt("DBPort") + c.DBUser = viper.GetString("DBUser") + c.DBPassword = viper.GetString("DBPassword") + c.DBDBName = viper.GetString("DBDBName") + c.DBOptions = viper.GetString("DBOptions") + c.DBOptions = viper.GetString("DBPath") +} |
