mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
add a configuration file (#453)
* complete updated config package * use envconfig+toml instead of viper. Add descriptions in example config file * add unit tests * debug gofmt on build server * force dummy commit * skip gofmt to validate other tests are passing * unset env vars for example file parsing test * cleanup tests * test improvements * re-enable gofmt * naming * PR comments * fix failing test after olympus default endpoint change * remove rdbms config * set defaults in code * add support for proxyfilteroff * add basic auth params * update gopkg.lock * undo gopkg.lock changes made during merge * remove defaults * explicitly specify all env variables * remove rdbms from example * remove user and pass to disable basic auth by default * switch to memory by default for the proxy * fix tests after config file change
This commit is contained in:
committed by
Marwan Sulaiman
parent
df14f2b691
commit
7c745fb3d9
@@ -0,0 +1,66 @@
|
||||
package config
|
||||
|
||||
import validator "gopkg.in/go-playground/validator.v9"
|
||||
|
||||
// StorageConfig provides configs for various storage backends
|
||||
type StorageConfig struct {
|
||||
CDN *CDNConfig `validate:""`
|
||||
Disk *DiskConfig `validate:""`
|
||||
GCP *GCPConfig `validate:""`
|
||||
Minio *MinioConfig `validate:""`
|
||||
Mongo *MongoConfig `validate:""`
|
||||
}
|
||||
|
||||
func setStorageTimeouts(s *StorageConfig, defaultTimeout int) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
if s.CDN != nil && s.CDN.Timeout == 0 {
|
||||
s.CDN.Timeout = defaultTimeout
|
||||
}
|
||||
if s.GCP != nil && s.GCP.Timeout == 0 {
|
||||
s.GCP.Timeout = defaultTimeout
|
||||
}
|
||||
if s.Minio != nil && s.Minio.Timeout == 0 {
|
||||
s.Minio.Timeout = defaultTimeout
|
||||
}
|
||||
if s.Mongo != nil && s.Mongo.Timeout == 0 {
|
||||
s.Mongo.Timeout = defaultTimeout
|
||||
}
|
||||
}
|
||||
|
||||
// envconfig initializes *all* struct pointers, even if there are no corresponding defaults or env variables
|
||||
// deleteInvalidStorageConfigs prunes all such invalid configurations
|
||||
func deleteInvalidStorageConfigs(s *StorageConfig) {
|
||||
validate := validator.New()
|
||||
|
||||
if s.CDN != nil {
|
||||
if err := validate.Struct(s.CDN); err != nil {
|
||||
s.CDN = nil
|
||||
}
|
||||
}
|
||||
|
||||
if s.Disk != nil {
|
||||
if err := validate.Struct(s.Disk); err != nil {
|
||||
s.Disk = nil
|
||||
}
|
||||
}
|
||||
|
||||
if s.GCP != nil {
|
||||
if err := validate.Struct(s.GCP); err != nil {
|
||||
s.GCP = nil
|
||||
}
|
||||
}
|
||||
|
||||
if s.Minio != nil {
|
||||
if err := validate.Struct(s.Minio); err != nil {
|
||||
s.Minio = nil
|
||||
}
|
||||
}
|
||||
|
||||
if s.Mongo != nil {
|
||||
if err := validate.Struct(s.Mongo); err != nil {
|
||||
s.Mongo = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user