utils

package
v0.0.0-...-93144e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvProd    = "production" // 生产环境
	EnvTesting = "testing"    // 测试环境
	EnvCI      = "test_ci"    // CI 环境
	EnvDevelop = "develop"    // 开发环境

	NonSandboxDeployID = "0" // 非联调环境部署Id
)

Variables

View Source
var (
	AppName      string // 应用名称
	AppVersion   string // 应用版本
	BuildVersion string // 编译版本
	BuildTime    string // 编译时间
	GitRevision  string // Git版本
	GitBranch    string // Git分支
	GoVersion    string // Golang信息
)

Functions

func App

func App() string

func EnableDebug

func EnableDebug()

func Env

func Env() string

func IsCIEnv

func IsCIEnv() bool

func IsDebug

func IsDebug() bool

func IsDevelopEnv

func IsDevelopEnv() bool

func IsProductionEnv

func IsProductionEnv() bool

func IsTestingEnv

func IsTestingEnv() bool

func PrintBuildInfo

func PrintBuildInfo()

Print your build info

Need add build flags

go build -ldflags "
	-X 'github.com/everywan/commons/utils.AppName=${APP_NAME}'             \
	-X 'github.com/everywan/commons/utils.AppVersion=${APP_VERSION}'       \
	-X 'github.com/everywan/commons/utils.BuildVersion=${BUILD_VERSION}'   \
	-X 'github.com/everywan/commons/utils.BuildTime=${BUILD_TIME}'         \
	-X 'github.com/everywan/commons/utils.GitRevision=${GIT_REVISION}'     \
	-X 'github.com/everywan/commons/utils.GitBranch=${GIT_BRANCH}'         \
	-X 'github.com/everywan/commons/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

func SafeGoWithError(fn func() error, errHandler func(error))

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

func SafeRunWithError(fn func() error) (err error)

SafeRun sync run a func with error. If the func panics, the panic value is returned as an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL