Better config handling with constants #83
|
@ -29,10 +29,73 @@ import (
|
||||||
// Key is used as a config key
|
// Key is used as a config key
|
||||||
type Key string
|
type Key string
|
||||||
|
|
||||||
|
// These constants hold all config value keys
|
||||||
const (
|
const (
|
||||||
ServiceJWTSecret Key = `service.JWTSecret`
|
ServiceJWTSecret Key = `service.JWTSecret`
|
||||||
|
ServiceInterface Key = `service.interface`
|
||||||
|
ServiceFrontendurl Key = `service.frontendurl`
|
||||||
|
ServiceEnableCaldav Key = `service.enablecaldav`
|
||||||
|
ServiceRootpath Key = ``
|
||||||
|
ServicePageCount Key = ``
|
||||||
|
ServiceEnableMetrics Key = ``
|
||||||
|
|
||||||
|
DatabaseType Key = ``
|
||||||
|
DatabaseHost Key = ``
|
||||||
|
DatabaseUser Key = ``
|
||||||
|
DatabasePassword Key = ``
|
||||||
|
DatabaseDatabase Key = ``
|
||||||
|
DatabasePath Key = ``
|
||||||
|
DatabaseMaxOpenConnections Key = ``
|
||||||
|
DatabaseMaxIdleConnections Key = ``
|
||||||
|
DatabaseMaxConnectionLifetime Key = ``
|
||||||
|
|
||||||
|
CacheEnabled Key = ``
|
||||||
|
CacheType Key = ``
|
||||||
|
CacheMaxElementSize Key = ``
|
||||||
|
|
||||||
|
MailerEnabled Key = ``
|
||||||
|
MailerHost Key = ``
|
||||||
|
MailerPort Key = ``
|
||||||
|
MailerUser Key = ``
|
||||||
|
MailerPassword Key = ``
|
||||||
|
MailerSkipTLSVerify Key = ``
|
||||||
|
MailerFromEmail Key = ``
|
||||||
|
MailerQueuelength Key = ``
|
||||||
|
MailerQueueTimeout Key = ``
|
||||||
|
|
||||||
|
RedisEnabled Key = ``
|
||||||
|
RedisHost Key = ``
|
||||||
|
RedisPassword Key = ``
|
||||||
|
RedisDB Key = ``
|
||||||
|
|
||||||
|
LogEnabled Key = ``
|
||||||
|
LogErrors Key = ``
|
||||||
|
LogStandard Key = ``
|
||||||
|
LogHttp Key = ``
|
||||||
|
LogEcho Key = ``
|
||||||
|
LogPath Key = ``
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetString returns a string config value
|
||||||
|
func (k Key) GetString() string {
|
||||||
|
return viper.GetString(string(k))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetBool returns a bool config value
|
||||||
|
func (k Key) GetBool() bool {
|
||||||
|
return viper.GetBool(string(k))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInt returns an int64 config value
|
||||||
|
func (k Key) GetInt() int64 {
|
||||||
|
return viper.GetInt64(string(k))
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets the default config value
|
||||||
|
func (k Key) setDefault(i interface{}) {
|
||||||
|
viper.SetDefault(string(k), i)
|
||||||
|
}
|
||||||
|
|
||||||
// InitConfig initializes the config, sets defaults etc.
|
// InitConfig initializes the config, sets defaults etc.
|
||||||
func InitConfig() {
|
func InitConfig() {
|
||||||
|
|
||||||
|
@ -44,10 +107,10 @@ func InitConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service
|
// Service
|
||||||
viper.SetDefault("service.JWTSecret", random)
|
ServiceJWTSecret.setDefault(random)
|
||||||
viper.SetDefault("service.interface", ":3456")
|
ServiceInterface.setDefault(":3456")
|
||||||
viper.SetDefault("service.frontendurl", "")
|
ServiceFrontendurl.setDefault("")
|
||||||
viper.SetDefault("service.enablecaldav", true)
|
ServiceEnableCaldav.setDefault(true)
|
||||||
|
|
||||||
ex, err := os.Executable()
|
ex, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user