Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/env

env

go
import "gitlab.soludian.com/soludian/fountain/libs/env"

Index

Constants

go
const KPackageName = "env"

Variables

go
var (

    // Setup when build using ldflags
    CommitSHA = "dev"
    BuildAt   = "2006-01-02T15:04:05Z07:00"
)

go
var (
    LogEventAppKeyDefault    = "fountain_log_event"
    LogEventSecretKeyDefault = "this_is_fountain_event_log"
    LogEventPlatformDefault  = "fountain_client"
    LogEventLogTypeDefault   = "event_log"

    LogEventTypeInstalled  = "Installed"
    LogEventTypeRegistered = "Registered"
)

go
var DecoderTagNameConf = func(d *mapstructure.DecoderConfig) {
    d.TagName = "conf"
    d.WeaklyTypedInput = true
}

func DetectExecutionMode

go
func DetectExecutionMode() string

func EnvAsSlice

go
func EnvAsSlice(envVar string) []string

EnvOrStr returns an env variable's value if it is exists or the default if not

func EnvOrBool

go
func EnvOrBool(envVar string, defaultValue bool) bool

EnvOrBool ...

func EnvOrFloat64

go
func EnvOrFloat64(envVar string, defaultValue float64) float64

EnvOrFloat64 ...

func EnvOrInt

go
func EnvOrInt(envVar string, defaultValue int) int

EnvOrInt ...

func EnvOrStr

go
func EnvOrStr(key, defaultValue string) string

EnvOrStr returns an env variable's value if it is exists or the default if not

func EnvOrUint

go
func EnvOrUint(envVar string, defaultValue uint) uint

EnvOrUint ...

func GetAddr

go
func GetAddr() string

Get the app's address

func GetAppBuildTime

go
func GetAppBuildTime() string

Get app's app version

func GetAppImage

go
func GetAppImage() string

Get app's image

func GetAppVersion

go
func GetAppVersion() string

Get app's version

func GetComponentName

go
func GetComponentName() string

Get app's component name

func GetComponentNameSnake

go
func GetComponentNameSnake() string

return snake case format

func GetConfigPath

go
func GetConfigPath() string

func GetDCName

go
func GetDCName() string

Get the data center name

func GetDeployAt

go
func GetDeployAt() string

func GetDomain

go
func GetDomain(includeSchema ...bool) string

Get the app's domain

func GetEndpointPrefix

go
func GetEndpointPrefix() string

Get app's endpoint prefix

func GetEnvironment

go
func GetEnvironment() string

Get the environment in which the application runs

func GetFountainVersion

go
func GetFountainVersion() string

Get the fountain version in which the application runs

func GetFullAppService

go
func GetFullAppService(pkgName string) string

Format: <appName>_<partOf>_<serviceName>_<pkgName>

func GetFullAppServiceServer

go
func GetFullAppServiceServer(pkgName string) string

Format: <appName>_<partOf>_<serviceName>_<pkgName>_<serviceID>

func GetGoVersion

go
func GetGoVersion() string

Get the go version in which the application runs

func GetK8SServiceAddr

go
func GetK8SServiceAddr() string

func GetLogExtraKeys

go
func GetLogExtraKeys() []string

Gets app's logExtraKeys

func GetLogFileLevel

go
func GetLogFileLevel() string

Gets app's logFileLevel

func GetLogPath

go
func GetLogPath() string

Get app's log path

func GetLogPrefix

go
func GetLogPrefix() string

Get app's log path prefix

func GetLogPrintLevel

go
func GetLogPrintLevel() string

Gets app's logPrintLevel

func GetLogTimeType

go
func GetLogTimeType() string

Gets app's logTimeType

func GetLogWriter

go
func GetLogWriter() string

func GetMaxProcesses

go
func GetMaxProcesses() int

Get the max processes in which the application runs

func GetNamespace

go
func GetNamespace() string

func GetNodeIP

go
func GetNodeIP() string

Get app's node name

func GetNodeName

go
func GetNodeName() string

Get app's node name

func GetPartOf

go
func GetPartOf() string

Get app's part of

func GetPartOfSnake

go
func GetPartOfSnake() string

return snake case format

func GetPrintVersion

go
func GetPrintVersion() string

func GetRegion

go
func GetRegion() string

Get the region where the APP runs

func GetSampleRate

go
func GetSampleRate() float64

func GetSentryDNS

go
func GetSentryDNS() string

Gets app's SentryDNS

func GetServerID

go
func GetServerID() string

Get app server's id ~ pod id

func GetServiceName

go
func GetServiceName() string

Get app's service name

func GetServiceNameSnake

go
func GetServiceNameSnake() string

return snake case format

func GetStartTime

go
func GetStartTime() string

Get the start time in which the application runs

func GetTraceIDName

go
func GetTraceIDName() string

Gets app's traceIDName

func GetZone

go
func GetZone() string

Get the availability zone where the app is running

func HasShellEnv

go
func HasShellEnv(shell string) bool

HasShellEnv has shell env check.

Usage:

HasShellEnv("sh")
HasShellEnv("sh")

func IsConsole

go
func IsConsole(out io.Writer) bool

IsConsole check out is console env. alias of the sys_util.IsConsole()

func IsDebugMode

go
func IsDebugMode() bool

IsDebugMode determines whether it is a test mode

func IsDevEnvironment

go
func IsDevEnvironment() bool

func IsDisableAuxiliary

go
func IsDisableAuxiliary() bool

func IsGithubActions

go
func IsGithubActions() bool

IsGithubActions env

func IsGovernanceEnabled

go
func IsGovernanceEnabled() bool

IsGovernanceEnable determines whether it is a governance enabled

func IsLinux

go
func IsLinux() bool

IsLinux system

func IsLocalEnvironment

go
func IsLocalEnvironment() bool

func IsMSys

go
func IsMSys() bool

IsMSys msys(MINGW64) env. alias of the sys_util.IsMSys()

func IsMac

go
func IsMac() bool

IsMac system

func IsMetricsEnabled

go
func IsMetricsEnabled() bool

IsMetricsEnabled determines whether it is a metrics enabled

func IsProdEnvironment

go
func IsProdEnvironment() bool

func IsRuntimeDebugMode

go
func IsRuntimeDebugMode() bool

func IsRuntimeTestingMode

go
func IsRuntimeTestingMode() bool

func IsSupport256Color

go
func IsSupport256Color() bool

IsSupport256Color render

func IsSupportColor

go
func IsSupportColor() bool

IsSupportColor check current console is support color.

Supported:

linux, mac, or windows's ConEmu, Cmder, putty, git-bash.exe

Not support:

windows cmd.exe, powerShell.exe

func IsSupportTrueColor

go
func IsSupportTrueColor() bool

IsSupportTrueColor render. IsSupportRGBColor

func IsTerminal

go
func IsTerminal(fd uintptr) bool

IsTerminal isatty check

Usage:

envutil.IsTerminal(os.Stdout.Fd())

func IsWSL

go
func IsWSL() bool

IsWSL system env https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364

func IsWatchConfigEnabled

go
func IsWatchConfigEnabled() bool

func IsWin

go
func IsWin() bool

IsWin system. linux windows darwin

func IsWindows

go
func IsWindows() bool

IsWindows system. alias of IsWin

func LoggerAddAppEnabled

go
func LoggerAddAppEnabled() bool

LoggerAddAppEnabled whether the log records the application name information

func PrintVersion

go
func PrintVersion()

PrintVersion print formatted version info

func SetAddr

go
func SetAddr(a string)

Set the app's address

func SetAuxiliaryDisable

go
func SetAuxiliaryDisable(disable ...bool)

SetMetricsDisable determines whether it is a governance enabled

func SetDebugMode

go
func SetDebugMode(flag ...bool)

Set debug mode "true" or "false"

func SetGovernanceEnable

go
func SetGovernanceEnable(enable ...bool)

SetGovernanceEnable determines whether it is a governance enabled

func SetMetricsDisable

go
func SetMetricsDisable(disable ...bool)

SetMetricsDisable determines whether it is a governance enabled

func SetupConfigEnv

go
func SetupConfigEnv()

func StdIsTerminal

go
func StdIsTerminal() bool

StdIsTerminal os.Stdout is terminal

type EnvConfig

go
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

go
func DefaultConfig() *EnvConfig

Generated by gomarkdoc