mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
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:
committed by
Aaron Schlesinger
parent
2cf10c3ead
commit
c3d1d14d23
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user