github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/utils/env.go (about) 1 package utils 2 3 type AresEnv string 4 5 const ( 6 EnvProd AresEnv = "production" 7 EnvStaging AresEnv = "staging" 8 EnvDev AresEnv = "development" 9 EnvTest AresEnv = "test" 10 11 EnvironmentKey = "ENVIRONMENT" 12 RuntimeEnvironmentKey = "RUNTIME_ENVIRONMENT" 13 ZoneKey = "DATACENTER_ZONE" 14 DataCenterKey = "DATACENTER" 15 DeploymentKey = "DEPLOYMENT_NAME" 16 HostnameKey = "HOSTNAME" 17 PortSystemKey = "PORT_SYSTEM" 18 AppIDKey = "APP_ID" 19 InstanceIDKey = "INSTANCE_ID" 20 ConfigDirKey = "UBER_CONFIG_DIR" 21 ) 22 23 type EnvironmentContext struct { 24 // Environment is // enum for host-level environment (development, test, production, staging) 25 Environment string 26 // RuntimeEnvironment is user-specified service runtime environment 27 RuntimeEnvironment string 28 // Zone is data center 29 Zone string 30 // Hostname is the host name 31 Hostname string 32 // Deployment is the deployment name 33 Deployment string // t.uber.com/udeploy_env 34 // SystemPort is for health checks and introspection 35 SystemPort string 36 // ApplicationID is application name 37 ApplicationID string 38 // InstanceID is the ID of an application instance 39 InstanceID string 40 } 41 42 // GetAresEnv gets the running environment setting for ares 43 func GetAresEnv() AresEnv { 44 aresEnv := AresEnv(GetConfig().Env) 45 switch aresEnv { 46 case EnvProd: 47 break 48 case EnvStaging: 49 break 50 case EnvDev: 51 break 52 case EnvTest: 53 break 54 default: 55 return EnvDev 56 } 57 return aresEnv 58 } 59 60 func IsTest() bool { 61 return GetAresEnv() == EnvTest 62 } 63 64 func IsDev() bool { 65 return GetAresEnv() == EnvDev 66 } 67 68 func IsProd() bool { 69 return GetAresEnv() == EnvProd 70 } 71 72 func IsStaging() bool { 73 return GetAresEnv() == EnvStaging 74 }