mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
config: accept PORT env + ensure colon (#1181)
* config: accept PORT env + ensure colon * ensure precedence
This commit is contained in:
committed by
Aaron Schlesinger
parent
f14707e5e5
commit
71aeca7f30
@@ -160,12 +160,27 @@ func envOverride(config *Config) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
portEnv := os.Getenv("PORT")
|
||||
// ATHENS_PORT takes precedence over PORT
|
||||
if portEnv != "" && os.Getenv("ATHENS_PORT") == "" {
|
||||
config.Port = portEnv
|
||||
}
|
||||
if config.Port == "" {
|
||||
config.Port = defaultPort
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ensurePortFormat(s string) string {
|
||||
if len(s) == 0 {
|
||||
return ""
|
||||
}
|
||||
if s[0] != ':' {
|
||||
return ":" + s
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func validateConfig(config Config) error {
|
||||
validate := validator.New()
|
||||
err := validate.StructExcept(config, "Storage")
|
||||
|
||||
Reference in New Issue
Block a user