New constructs and returns a new validated config. Empty string params will fall back to environment variables and defaults.
(p Params)
| 84 | // New constructs and returns a new validated config. |
| 85 | // Empty string params will fall back to environment variables and defaults. |
| 86 | func New(p Params) (Config, error) { |
| 87 | c := Config{ |
| 88 | Port: getOrEnv(p.Port, "PORT", "3001"), |
| 89 | BaseURL: getOrEnv(p.BaseURL, "BaseURL", "http://localhost:3001"), |
| 90 | DBPath: getOrEnv(p.DBPath, "DBPath", DefaultDBPath), |
| 91 | DisableRegistration: p.DisableRegistration || readBoolEnv("DisableRegistration"), |
| 92 | LogLevel: getOrEnv(p.LogLevel, "LOG_LEVEL", "info"), |
| 93 | AssetBaseURL: "/static", |
| 94 | HTTP500Page: assets.MustGetHTTP500ErrorPage(), |
| 95 | } |
| 96 | |
| 97 | if err := validate(c); err != nil { |
| 98 | return Config{}, err |
| 99 | } |
| 100 | |
| 101 | return c, nil |
| 102 | } |
| 103 | |
| 104 | func validate(c Config) error { |
| 105 | if _, err := url.ParseRequestURI(c.BaseURL); err != nil { |
no test coverage detected