diff --git a/config/config.go b/config/config.go index 0a28e783f2bbfc5d7f23edc3f4f00b02464426f1..3180492f39c2ba6e3062f5b587d7039fdd92816f 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "log" + "path/filepath" "github.com/meowgorithm/babyenv" ) @@ -15,14 +16,27 @@ type Callbacks interface { // Config is the configuration for Soft Serve. type Config struct { - Host string `env:"SOFT_SERVE_HOST" default:""` - Port int `env:"SOFT_SERVE_PORT" default:"23231"` - KeyPath string `env:"SOFT_SERVE_KEY_PATH" default:".ssh/soft_serve_server_ed25519"` - RepoPath string `env:"SOFT_SERVE_REPO_PATH" default:".repos"` - InitialAdminKey string `env:"SOFT_SERVE_INITIAL_ADMIN_KEY" default:""` + Host string `env:"SOFT_SERVE_HOST"` + Port int `env:"SOFT_SERVE_PORT"` + KeyPath string `env:"SOFT_SERVE_KEY_PATH"` + RepoPath string `env:"SOFT_SERVE_REPO_PATH"` + InitialAdminKey string `env:"SOFT_SERVE_INITIAL_ADMIN_KEY"` Callbacks Callbacks } +func (c *Config) applyDefaults() { + if c.Port == 0 { + c.Port = 23231 + } + if c.KeyPath == "" { + // NB: cross-platform-compatible path + c.KeyPath = filepath.Join(".ssh", "soft_serve_server_ed25519") + } + if c.RepoPath == "" { + c.RepoPath = ".repos" + } +} + // DefaultConfig returns a Config with the values populated with the defaults // or specified environment variables. func DefaultConfig() *Config { @@ -31,6 +45,7 @@ func DefaultConfig() *Config { if err != nil { log.Fatalln(err) } + scfg.applyDefaults() return scfg.WithCallbacks(nil) }