diff --git a/config.dev.toml b/config.dev.toml index 593a08c7..ecc3b850 100755 --- a/config.dev.toml +++ b/config.dev.toml @@ -2,6 +2,9 @@ # Most properties can be overridden with environment variables specified in this file # Most properties also have defaults (mentioned in this file) if they are not set in either the config file or the corresponding environment variable +# If you put this file where you start Athens from as "athens.toml", athens will use it when starting. +# You can also start athens with -config_file as command line argument to point out a config file. + # GoBinary returns the path to the go binary to use. This value can be a name of a binary in your PATH, or the full path # Defaults to "go" # Env override: GO_BINARY_PATH diff --git a/pkg/config/config.go b/pkg/config/config.go index 945588a1..613798e5 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -13,6 +13,8 @@ import ( validator "gopkg.in/go-playground/validator.v9" ) +const defaultConfigFile = "athens.toml" + // Config provides configuration values for all components type Config struct { TimeoutConf @@ -47,14 +49,22 @@ type Config struct { // 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 + // User explicitly specified a config file + if configFile != "" { + return ParseConfigFile(configFile) } - return ParseConfigFile(configFile) + + // There is a config in the current directory + if fi, err := os.Stat(defaultConfigFile); err == nil { + return ParseConfigFile(fi.Name()) + } + + // Use default values + log.Println("Running dev mode with default settings, consult config when you're ready to run in production") + return defaultConfig(), nil } -func createDefault() *Config { +func defaultConfig() *Config { return &Config{ GoBinary: "go", GoEnv: "development", diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 4a3d08e5..dea1bbe2 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -413,7 +413,7 @@ func TestDefaultConfigMatchesConfigFile(t *testing.T) { t.Errorf("Unable to parse example config file: %+v", err) } - defConf := createDefault() + defConf := defaultConfig() ignoreStorageOpts := cmpopts.IgnoreTypes(&StorageConfig{}) ignoreGoEnvOpts := cmpopts.IgnoreFields(Config{}, "GoEnv")