-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
configuration.go
31 lines (27 loc) · 1.15 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package configuration
import (
"time"
"github.com/caarlos0/env/v11"
log "github.com/sirupsen/logrus"
)
// Config struct for configuration environmental variables
type Config struct {
ServerHost string `env:"SERVER_HOST" envDefault:"localhost"`
ServerPort int `env:"SERVER_PORT" envDefault:"8888"`
HealthzHost string `env:"HEALTHZ_HOST" envDefault:"0.0.0.0"`
HealthzPort int `env:"HEALTHZ_PORT" envDefault:"8080"`
ServerReadTimeout time.Duration `env:"SERVER_READ_TIMEOUT"`
ServerWriteTimeout time.Duration `env:"SERVER_WRITE_TIMEOUT"`
DomainFilter []string `env:"DOMAIN_FILTER" envDefault:""`
ExcludeDomains []string `env:"EXCLUDE_DOMAIN_FILTER" envDefault:""`
RegexDomainFilter string `env:"REGEXP_DOMAIN_FILTER" envDefault:""`
RegexDomainExclusion string `env:"REGEXP_DOMAIN_FILTER_EXCLUSION" envDefault:""`
}
// Init sets up configuration by reading set environmental variables
func Init() Config {
cfg := Config{}
if err := env.Parse(&cfg); err != nil {
log.Fatalf("error reading configuration from environment: %v", err)
}
return cfg
}