summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorMax2018-02-05 02:54:46 +0100
committerMax2018-02-05 02:54:46 +0100
commit91c901a764dbf2d600366ed1d8ee19c813d3047d (patch)
tree20ac392dc96bf80d48b278f5027a4b44a257dfaf /config.go
parent543ebae42be1b7385e476a4699a7f88e95a2d120 (diff)
downloadalkobote-91c901a764dbf2d600366ed1d8ee19c813d3047d.tar.gz
Adds some database code.
Diffstat (limited to 'config.go')
-rw-r--r--config.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/config.go b/config.go
index f877eba..30387a3 100644
--- a/config.go
+++ b/config.go
@@ -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")
+}