utils

package
v0.0.0-...-389bc3b Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")

StdChars standard characters allowed in uniuri string.

View Source
var StdNumbers = []byte("0123456789")

StdNumbers base random numbers

Functions

func Caller

func Caller() (name string)

Caller 返回上一层调用者的函数信息 例如:

func abc() {
	Caller()  这里就会返回 abc
}

func FuncTrace

func FuncTrace(xl *log.Logger) func()

FuncTrace 记录函数的执行时间

func NewRandomChars

func NewRandomChars(length int, chars []byte) (s string)

NewRandomChars returns a new random string of the provided length, consisting of the provided byte slice of allowed characters (maximum 256).

func NewRandomNumber

func NewRandomNumber(length int) string

NewRandomNumber return a random number string

func NewRandomStr

func NewRandomStr(length int) string

NewRandomStr returns a new random string of the provided length, consisting of standard characters.

func Truncate

func Truncate(str string, limit int) string

Truncate a given text after a given length if text is longer than length

func WithRetry

func WithRetry(f func() error)

WithRetry 执行某个函数,如果返回错误,那么在 10 分钟内重复执行,每执行一次,sleep 的时间左移一位

func WithRetryTimesInterval

func WithRetryTimesInterval(f func() error, times, intervalSec int)

WithRetryTimesInterval 重试

func WithShortRetry

func WithShortRetry(f func() error)

WithShortRetry 执行某个函数,如果返回错误,那么2s 后重试, 重试5次

Types

type SecurityMap

type SecurityMap struct {
	// contains filtered or unexported fields
}

func NewSecurityMap

func NewSecurityMap() *SecurityMap

func (*SecurityMap) Edit

func (sm *SecurityMap) Edit(key string, fn func(key string, value interface{}) (interface{}, error)) error

func (*SecurityMap) Get

func (sm *SecurityMap) Get(key string) (value interface{})

func (*SecurityMap) Has

func (sm *SecurityMap) Has(key string) bool

func (*SecurityMap) Range

func (sm *SecurityMap) Range(fn func(key string, value interface{}) bool)

func (*SecurityMap) Set

func (sm *SecurityMap) Set(key string, value interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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