@ -23,6 +23,7 @@ type Configuration struct {
AuthBackend string ` yaml:"AuthBackend" env:"AUTH_BACKEND" `
UseSSL bool ` yaml:"EnableSSL" env:"USE_SSL" `
EnableDebugMode bool ` yaml:"EnableDebugMode" env:"ENABLE_DEBUG_MODE" `
EnableColorLogs bool ` yaml:"EnableColorLogs" env:"ENABLE_COLOR_LOGS" `
ShortedIDLength int ` yaml:"ShortedIDLength" env:"SHORTED_ID_LENGTH" `
Google oAuthConf ` yaml:"Google" env:"GOOGLE" `
GitHub oAuthConf ` yaml:"GitHub" env:"GITHUB" `
@ -42,12 +43,13 @@ type proxyAuthConf struct {
}
// config contains the default values
var c onfig = Configuration {
var C onfig = Configuration {
ListenAddr : ":8080" ,
BaseURL : "http://localhost:3000" ,
DataDir : "data" ,
Backend : "boltdb" ,
EnableDebugMode : false ,
EnableColorLogs : true ,
UseSSL : false ,
ShortedIDLength : 4 ,
AuthBackend : "oauth" ,
@ -57,7 +59,7 @@ var config = Configuration{
func ReadInConfig ( ) error {
file , err := ioutil . ReadFile ( "config.yaml" )
if err == nil {
if err := yaml . Unmarshal ( file , & c onfig) ; err != nil {
if err := yaml . Unmarshal ( file , & C onfig) ; err != nil {
return errors . Wrap ( err , "could not unmarshal yaml file" )
}
} else if ! os . IsNotExist ( err ) {
@ -65,15 +67,16 @@ func ReadInConfig() error {
} else {
logrus . Info ( "No configuration file found, using defaults with environment variable overrides." )
}
if err := envstruct . ApplyEnvVars ( & c onfig, "GUS" ) ; err != nil {
if err := envstruct . ApplyEnvVars ( & C onfig, "GUS" ) ; err != nil {
return errors . Wrap ( err , "could not apply environment configuration" )
}
config . DataDir , err = filepath . Abs ( config . DataDir )
logrus . Info ( "Loaded configuration: %v" , Config )
Config . DataDir , err = filepath . Abs ( Config . DataDir )
if err != nil {
return errors . Wrap ( err , "could not get relative data dir path" )
}
if _ , err = os . Stat ( c onfig. DataDir ) ; os . IsNotExist ( err ) {
if err = os . MkdirAll ( c onfig. DataDir , 0755 ) ; err != nil {
if _ , err = os . Stat ( C onfig. DataDir ) ; os . IsNotExist ( err ) {
if err = os . MkdirAll ( C onfig. DataDir , 0755 ) ; err != nil {
return errors . Wrap ( err , "could not create config directory" )
}
}
@ -86,10 +89,10 @@ func (o oAuthConf) Enabled() bool {
// GetConfig returns the configuration from the memory
func GetConfig ( ) Configuration {
return c onfig
return C onfig
}
// SetConfig sets the configuration into the memory
func SetConfig ( c Configuration ) {
c onfig = c
C onfig = c
}