-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.go
34 lines (28 loc) · 857 Bytes
/
config.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
32
33
34
package config
import (
"github.com/kelseyhightower/envconfig"
)
const (
envDevelopment = "development"
envProduction = "production"
)
// Env stores configuration settings extract from enviromental variables
// by using https://github.com/kelseyhightower/envconfig
type Env struct {
// LogLevel is INFO or DEBUG. Default is "INFO".
LogLevel string `envconfig:"LOG_LEVEL" default:"INFO"`
// Env is environment where application is running The value must be
// "development" or "production".
Env string `envconfig:"ENV" required:"true"`
// Port is http serve port.
Port int `envconfig:"PORT" default:"8000"`
}
// ReadFromEnv reads configuration from environmental variables
// defined by Env struct.
func ReadFromEnv() (*Env, error) {
var env Env
if err := envconfig.Process("", &env); err != nil {
return nil, err
}
return &env, nil
}