-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.go
More file actions
39 lines (31 loc) · 741 Bytes
/
env.go
File metadata and controls
39 lines (31 loc) · 741 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
package slice
import (
"os"
"strings"
)
const (
envDev string = "dev"
envTest string = "test"
envProd string = "prod"
)
func parseEnv(env string) Env {
if env == "" {
return Env(envProd)
}
return Env(strings.ToLower(env))
}
var lookupEnv = os.LookupEnv
// Env
type Env string
// String converts environment value to predefined strings.
func (e Env) String() string {
return string(e)
}
// IsDev is a helper function to check whether app is running in Dev mode
func (e Env) IsDev() bool {
return strings.HasPrefix(strings.ToLower(string(e)), envDev)
}
// IsTest is a helper function to check whether app is running in Dev mode
func (e Env) IsTest() bool {
return strings.HasPrefix(strings.ToLower(string(e)), envTest)
}