MCPcopy Create free account
hub / github.com/DoNewsCode/core / NewEnv

Function NewEnv

config/env.go:61–76  ·  view source on GitHub ↗

NewEnv takes in environment string and returns a Env type. It does some "best-effort" normalization internally. For example, prod, PROD, production and PRODUCTION produces the same type. It is recommended to use one of "production", "staging", "development", "local", or "testing" as output to avoid

(env string)

Source from the content-addressed store, hash-verified

59// For example, prod, PROD, production and PRODUCTION produces the same type. It is recommended to use one of
60// "production", "staging", "development", "local", or "testing" as output to avoid unexpected outcome.
61func NewEnv(env string) Env {
62 switch strings.ToLower(env) {
63 case "production", "prod", "online":
64 return EnvProduction
65 case "pre-prod", "staging":
66 return EnvStaging
67 case "development", "develop", "dev":
68 return EnvDevelopment
69 case "local":
70 return EnvLocal
71 case "testing", "test":
72 return EnvTesting
73 default:
74 return EnvUnknown
75 }
76}
77
78// NewEnvFromConf reads the name of application from configuration's "env" entry.
79func NewEnvFromConf(conf contract.ConfigUnmarshaler) Env {

Callers 3

provideDefaultConfigFunction · 0.92
NewEnvFromConfFunction · 0.85
TestEnv_StringFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestEnv_StringFunction · 0.68