utils

package
v0.0.0-...-28a9172 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvProd    = "production" // 生产环境
	EnvStaging = "staging"    // 预发环境
	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 HandleInitError

func HandleInitError(module string, err error)

func IsCIEnv

func IsCIEnv() bool

func IsDebug

func IsDebug() bool

func IsDevelopEnv

func IsDevelopEnv() bool

func IsProdEnv

func IsProdEnv() 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

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.

func SandBoxID

func SandBoxID() string

Types

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

自定义 Set, 非并发安全

func NewSet

func NewSet[T comparable]() *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(key T)

func (*Set[T]) Del

func (s *Set[T]) Del(key T)

func (*Set[T]) Exist

func (s *Set[T]) Exist(key T) bool

func (*Set[T]) ToList

func (s *Set[T]) ToList() []T

Jump to

Keyboard shortcuts

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