-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.go
More file actions
41 lines (32 loc) · 713 Bytes
/
env.go
File metadata and controls
41 lines (32 loc) · 713 Bytes
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
35
36
37
38
39
40
41
package envmodel
import (
"os"
"strings"
)
const (
EnvDevelopment = "development"
EnvTest = "test"
EnvKey = "ENV"
)
type Environment struct {
EnvKey string
Env string
option *Option
}
func NewEnvironment(option ...*Option) *Environment {
opt := getOption(option...)
var env Environment
env.option = opt
env.EnvKey = EnvKey
if "" == opt.AppName {
env.EnvKey = strings.ToUpper(opt.AppName) + "_" + EnvKey
}
env.Env = os.Getenv(env.EnvKey)
if "" == env.Env {
env.Env = EnvDevelopment
opt.Logger.Info().Str("environment", env.Env).Msg("environment assumed")
} else {
opt.Logger.Info().Str("environment", env.Env).Msgf("environment set by %q", env.EnvKey)
}
return &env
}