From 91c901a764dbf2d600366ed1d8ee19c813d3047d Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 5 Feb 2018 02:54:46 +0100 Subject: Adds some database code. --- config.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'config.go') 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") +} -- cgit v1.2.3