Documentation ¶
Index ¶
- Constants
- Variables
- func App() string
- func EnableDebug()
- func Env() string
- func HandleInitError(module string, err error)
- func IsCIEnv() bool
- func IsDebug() bool
- func IsDevelopEnv() bool
- func IsProdEnv() bool
- func IsSandBoxEnv() bool
- func IsStagingEnv() bool
- func IsTestingEnv() bool
- func PrintBuildInfo()
- func SafeGo(fn func(), errHandler func(error))
- func SafeGoWithError(fn func() error, errHandler func(error))
- func SafeRun(fn func()) (err error)
- func SafeRunWithError(fn func() error) (err error)
- func SandBoxID() string
- type Set
Constants ¶
View Source
const ( EnvProd = "production" // 生产环境 EnvStaging = "staging" // 预发环境 EnvTesting = "testing" // 测试环境 EnvCI = "test_ci" // CI 环境 EnvDevelop = "develop" // 开发环境 // 沙盒环境 NonSandboxDeployID = "0" // 非联调环境部署Id )
Variables ¶
Functions ¶
func EnableDebug ¶
func EnableDebug()
func HandleInitError ¶
func IsDevelopEnv ¶
func IsDevelopEnv() bool
func IsSandBoxEnv ¶
func IsSandBoxEnv() bool
func IsStagingEnv ¶
func IsStagingEnv() bool
func IsTestingEnv ¶
func IsTestingEnv() bool
func PrintBuildInfo ¶
func PrintBuildInfo()
todo demo 替换为实际名. 打印程序构建信息, 需要在打包时注入变量. 程序实例参考 demo.
Need add build flags
APP_NAME := commons APP_VERSION := $(shell git describe --abbrev=0 --tags) BUILD_VERSION := $(shell git log -1 --oneline | base64) BUILD_TIME := $(shell date "+%FT%T%z") GIT_REVISION := $(shell git rev-parse --short HEAD) GIT_BRANCH := $(shell git name-rev --name-only HEAD) GO_VERSION := $(shell go version) go build -ldflags " -X 'github.com/everywan/common/utils.AppName=${APP_NAME}' \ -X 'github.com/everywan/common/utils.AppVersion=${APP_VERSION}' \ -X 'github.com/everywan/common/utils.BuildVersion=${BUILD_VERSION}' \ -X 'github.com/everywan/common/utils.BuildTime=${BUILD_TIME}' \ -X 'github.com/everywan/common/utils.GitRevision=${GIT_REVISION}' \ -X 'github.com/everywan/common/utils.GitBranch=${GIT_BRANCH}' \ -X 'github.com/everywan/common/utils.GoVersion=${GO_VERSION}' \ -s -w " -mod vendor -v -o $(NAME) ${MAIN}
func SafeGo ¶
func SafeGo(fn func(), errHandler func(error))
SafeGo async run a func. If the func panics, the panic value will be handle by errHandler.
func SafeGoWithError ¶
SafeGoWithError async run a func with error. If the func panics, the panic value will be handle by errHandler.
func SafeRun ¶
func SafeRun(fn func()) (err error)
SafeRun sync run a func. If the func panics, the panic value is returned as an error.
func SafeRunWithError ¶
SafeRun sync run a func with error. If the func panics, the panic value is returned as an error.
Types ¶
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
自定义 Set, 非并发安全
func NewSet ¶
func NewSet[T comparable]() *Set[T]
Click to show internal directories.
Click to hide internal directories.