Import path:
gitlab.soludian.com/soludian/fountain/libs/env
env
import "gitlab.soludian.com/soludian/fountain/libs/env"Index
- Constants
- Variables
- func DetectExecutionMode() string
- func EnvAsSlice(envVar string) []string
- func EnvOrBool(envVar string, defaultValue bool) bool
- func EnvOrFloat64(envVar string, defaultValue float64) float64
- func EnvOrInt(envVar string, defaultValue int) int
- func EnvOrStr(key, defaultValue string) string
- func EnvOrUint(envVar string, defaultValue uint) uint
- func GetAddr() string
- func GetAppBuildTime() string
- func GetAppImage() string
- func GetAppVersion() string
- func GetComponentName() string
- func GetComponentNameSnake() string
- func GetConfigPath() string
- func GetDCName() string
- func GetDeployAt() string
- func GetDomain(includeSchema ...bool) string
- func GetEndpointPrefix() string
- func GetEnvironment() string
- func GetFountainVersion() string
- func GetFullAppService(pkgName string) string
- func GetFullAppServiceServer(pkgName string) string
- func GetGoVersion() string
- func GetK8SServiceAddr() string
- func GetLogExtraKeys() []string
- func GetLogFileLevel() string
- func GetLogPath() string
- func GetLogPrefix() string
- func GetLogPrintLevel() string
- func GetLogTimeType() string
- func GetLogWriter() string
- func GetMaxProcesses() int
- func GetNamespace() string
- func GetNodeIP() string
- func GetNodeName() string
- func GetPartOf() string
- func GetPartOfSnake() string
- func GetPrintVersion() string
- func GetRegion() string
- func GetSampleRate() float64
- func GetSentryDNS() string
- func GetServerID() string
- func GetServiceName() string
- func GetServiceNameSnake() string
- func GetStartTime() string
- func GetTraceIDName() string
- func GetZone() string
- func HasShellEnv(shell string) bool
- func IsConsole(out io.Writer) bool
- func IsDebugMode() bool
- func IsDevEnvironment() bool
- func IsDisableAuxiliary() bool
- func IsGithubActions() bool
- func IsGovernanceEnabled() bool
- func IsLinux() bool
- func IsLocalEnvironment() bool
- func IsMSys() bool
- func IsMac() bool
- func IsMetricsEnabled() bool
- func IsProdEnvironment() bool
- func IsRuntimeDebugMode() bool
- func IsRuntimeTestingMode() bool
- func IsSupport256Color() bool
- func IsSupportColor() bool
- func IsSupportTrueColor() bool
- func IsTerminal(fd uintptr) bool
- func IsWSL() bool
- func IsWatchConfigEnabled() bool
- func IsWin() bool
- func IsWindows() bool
- func LoggerAddAppEnabled() bool
- func PrintVersion()
- func SetAddr(a string)
- func SetAuxiliaryDisable(disable ...bool)
- func SetDebugMode(flag ...bool)
- func SetGovernanceEnable(enable ...bool)
- func SetMetricsDisable(disable ...bool)
- func SetupConfigEnv()
- func StdIsTerminal() bool
- type EnvConfig
Constants
const KPackageName = "env"Variables
var (
// Setup when build using ldflags
CommitSHA = "dev"
BuildAt = "2006-01-02T15:04:05Z07:00"
)var (
LogEventAppKeyDefault = "fountain_log_event"
LogEventSecretKeyDefault = "this_is_fountain_event_log"
LogEventPlatformDefault = "fountain_client"
LogEventLogTypeDefault = "event_log"
LogEventTypeInstalled = "Installed"
LogEventTypeRegistered = "Registered"
)var DecoderTagNameConf = func(d *mapstructure.DecoderConfig) {
d.TagName = "conf"
d.WeaklyTypedInput = true
}func DetectExecutionMode
func DetectExecutionMode() stringfunc EnvAsSlice
func EnvAsSlice(envVar string) []stringEnvOrStr returns an env variable's value if it is exists or the default if not
func EnvOrBool
func EnvOrBool(envVar string, defaultValue bool) boolEnvOrBool ...
func EnvOrFloat64
func EnvOrFloat64(envVar string, defaultValue float64) float64EnvOrFloat64 ...
func EnvOrInt
func EnvOrInt(envVar string, defaultValue int) intEnvOrInt ...
func EnvOrStr
func EnvOrStr(key, defaultValue string) stringEnvOrStr returns an env variable's value if it is exists or the default if not
func EnvOrUint
func EnvOrUint(envVar string, defaultValue uint) uintEnvOrUint ...
func GetAddr
func GetAddr() stringGet the app's address
func GetAppBuildTime
func GetAppBuildTime() stringGet app's app version
func GetAppImage
func GetAppImage() stringGet app's image
func GetAppVersion
func GetAppVersion() stringGet app's version
func GetComponentName
func GetComponentName() stringGet app's component name
func GetComponentNameSnake
func GetComponentNameSnake() stringreturn snake case format
func GetConfigPath
func GetConfigPath() stringfunc GetDCName
func GetDCName() stringGet the data center name
func GetDeployAt
func GetDeployAt() stringfunc GetDomain
func GetDomain(includeSchema ...bool) stringGet the app's domain
func GetEndpointPrefix
func GetEndpointPrefix() stringGet app's endpoint prefix
func GetEnvironment
func GetEnvironment() stringGet the environment in which the application runs
func GetFountainVersion
func GetFountainVersion() stringGet the fountain version in which the application runs
func GetFullAppService
func GetFullAppService(pkgName string) stringFormat: <appName>_<partOf>_<serviceName>_<pkgName>
func GetFullAppServiceServer
func GetFullAppServiceServer(pkgName string) stringFormat: <appName>_<partOf>_<serviceName>_<pkgName>_<serviceID>
func GetGoVersion
func GetGoVersion() stringGet the go version in which the application runs
func GetK8SServiceAddr
func GetK8SServiceAddr() stringfunc GetLogExtraKeys
func GetLogExtraKeys() []stringGets app's logExtraKeys
func GetLogFileLevel
func GetLogFileLevel() stringGets app's logFileLevel
func GetLogPath
func GetLogPath() stringGet app's log path
func GetLogPrefix
func GetLogPrefix() stringGet app's log path prefix
func GetLogPrintLevel
func GetLogPrintLevel() stringGets app's logPrintLevel
func GetLogTimeType
func GetLogTimeType() stringGets app's logTimeType
func GetLogWriter
func GetLogWriter() stringfunc GetMaxProcesses
func GetMaxProcesses() intGet the max processes in which the application runs
func GetNamespace
func GetNamespace() stringfunc GetNodeIP
func GetNodeIP() stringGet app's node name
func GetNodeName
func GetNodeName() stringGet app's node name
func GetPartOf
func GetPartOf() stringGet app's part of
func GetPartOfSnake
func GetPartOfSnake() stringreturn snake case format
func GetPrintVersion
func GetPrintVersion() stringfunc GetRegion
func GetRegion() stringGet the region where the APP runs
func GetSampleRate
func GetSampleRate() float64func GetSentryDNS
func GetSentryDNS() stringGets app's SentryDNS
func GetServerID
func GetServerID() stringGet app server's id ~ pod id
func GetServiceName
func GetServiceName() stringGet app's service name
func GetServiceNameSnake
func GetServiceNameSnake() stringreturn snake case format
func GetStartTime
func GetStartTime() stringGet the start time in which the application runs
func GetTraceIDName
func GetTraceIDName() stringGets app's traceIDName
func GetZone
func GetZone() stringGet the availability zone where the app is running
func HasShellEnv
func HasShellEnv(shell string) boolHasShellEnv has shell env check.
Usage:
HasShellEnv("sh")
HasShellEnv("sh")func IsConsole
func IsConsole(out io.Writer) boolIsConsole check out is console env. alias of the sys_util.IsConsole()
func IsDebugMode
func IsDebugMode() boolIsDebugMode determines whether it is a test mode
func IsDevEnvironment
func IsDevEnvironment() boolfunc IsDisableAuxiliary
func IsDisableAuxiliary() boolfunc IsGithubActions
func IsGithubActions() boolIsGithubActions env
func IsGovernanceEnabled
func IsGovernanceEnabled() boolIsGovernanceEnable determines whether it is a governance enabled
func IsLinux
func IsLinux() boolIsLinux system
func IsLocalEnvironment
func IsLocalEnvironment() boolfunc IsMSys
func IsMSys() boolIsMSys msys(MINGW64) env. alias of the sys_util.IsMSys()
func IsMac
func IsMac() boolIsMac system
func IsMetricsEnabled
func IsMetricsEnabled() boolIsMetricsEnabled determines whether it is a metrics enabled
func IsProdEnvironment
func IsProdEnvironment() boolfunc IsRuntimeDebugMode
func IsRuntimeDebugMode() boolfunc IsRuntimeTestingMode
func IsRuntimeTestingMode() boolfunc IsSupport256Color
func IsSupport256Color() boolIsSupport256Color render
func IsSupportColor
func IsSupportColor() boolIsSupportColor check current console is support color.
Supported:
linux, mac, or windows's ConEmu, Cmder, putty, git-bash.exeNot support:
windows cmd.exe, powerShell.exefunc IsSupportTrueColor
func IsSupportTrueColor() boolIsSupportTrueColor render. IsSupportRGBColor
func IsTerminal
func IsTerminal(fd uintptr) boolIsTerminal isatty check
Usage:
envutil.IsTerminal(os.Stdout.Fd())func IsWSL
func IsWSL() boolIsWSL system env https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364
func IsWatchConfigEnabled
func IsWatchConfigEnabled() boolfunc IsWin
func IsWin() boolIsWin system. linux windows darwin
func IsWindows
func IsWindows() boolIsWindows system. alias of IsWin
func LoggerAddAppEnabled
func LoggerAddAppEnabled() boolLoggerAddAppEnabled whether the log records the application name information
func PrintVersion
func PrintVersion()PrintVersion print formatted version info
func SetAddr
func SetAddr(a string)Set the app's address
func SetAuxiliaryDisable
func SetAuxiliaryDisable(disable ...bool)SetMetricsDisable determines whether it is a governance enabled
func SetDebugMode
func SetDebugMode(flag ...bool)Set debug mode "true" or "false"
func SetGovernanceEnable
func SetGovernanceEnable(enable ...bool)SetGovernanceEnable determines whether it is a governance enabled
func SetMetricsDisable
func SetMetricsDisable(disable ...bool)SetMetricsDisable determines whether it is a governance enabled
func SetupConfigEnv
func SetupConfigEnv()func StdIsTerminal
func StdIsTerminal() boolStdIsTerminal os.Stdout is terminal
type EnvConfig
type EnvConfig struct {
Environment string `conf:"environment" json:"environment"` // AppMode
DisableAuxiliary bool `conf:"disable_auxiliary" json:"disable_auxiliary"` // Tuỳ chọn này sẽ tắt tất cả các server phụ trợ: debug, governance, metrics,..
DisableMetrics bool `conf:"disable_metrics" json:"disable_metrics"`
EnableGovernance bool `conf:"enable_governance" json:"enable_governance"`
MaxProcesses int `conf:"max_processes" json:"max_processes"`
ConfigPath string `conf:"config_path" json:"config_path"`
WatchConfig bool `conf:"watch_config" json:"watch_config"`
Region string `conf:"region" json:"region"`
Zone string `conf:"zone" json:"zone"`
DCName string `conf:"dc_name" json:"dc_name"`
Namespace string `conf:"namespace" json:"namespace"`
Debug bool `conf:"debug" json:"debug"`
// App -> Services -> Servers (Pods)
Addr string `conf:"addr" json:"addr"`
Domain string `conf:"domain" json:"domain"`
NodeName string `conf:"node_name" json:"node_name"` // appInstance
NodeIP string `conf:"node_ip" json:"node_ip"` // appInstance
ComponentName string `conf:"component_name" json:"component_name"` // name of the component: okela
PartOf string `conf:"part_of" json:"part_of"` // part of of the component: backend
AppVersion string `conf:"-" json:"app_version"`
ImageName string `conf:"image_name" json:"image_name"`
BuildTime string `conf:"-" json:"build_time"`
ServiceName string `conf:"service_name" json:"service_name"` // name of the service that app is serving; Normally the service name is the app name
ServerID string `conf:"server_id" json:"server_id"`
EndpointPrefix string `conf:"endpoint_prefix" json:"endpoint_prefix"`
K8sServerAddr string `conf:"k8s_server_addr" json:"k8s_server_addr"`
// --- Log
LogPath string `conf:"log_path" json:"log_path,omitempty"`
LogPrefix string `conf:"log_prefix" json:"log_prefix,omitempty"`
LogPrintLevel string `conf:"log_print_level" json:"log_print_level,omitempty"` // LogPrintLevel: trace, debug, info, warn, error, fatal, panic, disabled, no
LogFileLevel string `conf:"log_file_level" json:"log_file_level,omitempty"` // LogFileLevel: trace, debug, info, warn, error, fatal, panic, disabled, no
LogDescription string `conf:"log_description" json:"log_description,omitempty"`
TraceIDName string `conf:"trace_id_name" json:"trace_id_name,omitempty"`
LogExtraKeys []string `conf:"log_extra_keys" json:"log_extra_keys,omitempty"`
LogWriter string `conf:"log_writer" json:"log_writer,omitempty"`
LogAddApp bool `conf:"log_add_app" json:"log_add_app,omitempty"`
LogTimeType string `conf:"log_time_type" json:"log_time_type,omitempty"`
SentryDNS string `conf:"sentry_dns" json:"sentry_dns,omitempty"` // REVIEW: Có nên tách riêng ra không?
}func DefaultConfig
func DefaultConfig() *EnvConfigGenerated by gomarkdoc