Use default conf values if file not found (#1022)

* default conf if no file provided

* move to the config pkg

* rm default config path

* rm log
This commit is contained in:
marpio
2019-02-14 20:32:53 +01:00
committed by Aaron Schlesinger
parent 2cf10c3ead
commit c3d1d14d23
4 changed files with 32 additions and 64 deletions
+26
View File
@@ -2,6 +2,7 @@ package config
import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
@@ -41,6 +42,31 @@ type Config struct {
Storage *StorageConfig
}
// Load loads the config from a file.
// If file is not present returns default config
func Load(configFile string) (*Config, error) {
if configFile == "" {
log.Print("config file not provided - using default settings")
return createDefault(), nil
}
return ParseConfigFile(configFile)
}
func createDefault() *Config {
return &Config{
GoBinary: "go",
GoEnv: "development",
GoGetWorkers: 30,
ProtocolWorkers: 30,
LogLevel: "debug",
CloudRuntime: "none",
TimeoutConf: TimeoutConf{Timeout: 300},
StorageType: "memory",
Port: ":3000",
GlobalEndpoint: "http://localhost:3001",
}
}
// BasicAuth returns BasicAuthUser and BasicAuthPassword
// and ok if neither of them are empty
func (c *Config) BasicAuth() (user, pass string, ok bool) {