Documentation
¶
Index ¶
- Variables
- func AESDecrypt(src []byte, key []byte) ([]byte, error)
- func AESEncrypt(src []byte, key []byte) ([]byte, error)
- func AppendBytes(fpath string, bs []byte) error
- func Clamp[T cmp.Ordered](v, min, max T) T
- func FormatTime(t time.Time) string
- func MD5(s string) string
- func MapToSlice[K comparable, V, T any](m map[K]V, transFunc func(K, V) (T, bool)) []T
- func MapToSliceK[K comparable, V any](m map[K]V) []K
- func MapToSliceV[K comparable, V any](m map[K]V) []V
- func Must(i interface{}, e error) interface{}
- func Now() time.Time
- func RandMapK[K comparable, V any](m map[K]V, n int) []K
- func RandMapV[K comparable, V any](m map[K]V, n int) []V
- func RandSlice[T any](slice []T, n int) []T
- func RandSliceWeightFunc[T any](slice []T, weightFunc func(T) int) T
- func RandSliceWeightFuncN[T any](slice []T, n int, weightFunc func(T) int) []T
- func RandString(n int) string
- func ReadJson(fpath string, i interface{}) error
- func Recover()
- func RecoverF(f func(r interface{}))
- func SliceToMap[K comparable, V, T any](a []V, transFunc func(V) (K, T, bool)) map[K]T
- func SliceToSlice[T, V any](a []T, transFunc func(T) (V, bool)) []V
- func TopMapN[K comparable, V any](m map[K]V, n int, less func(V, V) bool) []V
- func TopSliceN[T any](a []T, n int, less func(T, T) bool) []T
- func WaitExitSignal()
- func WaitTimeoutFunc(timeout time.Duration, f func()) bool
- func WaitUntil(timeout time.Duration, f func() bool) bool
- func WriteBytes(fpath string, data []byte) error
- func WriteJson(fpath string, i interface{}) error
- type Duration
- type MysqlDSNCreator
- func (opts *MysqlDSNCreator) DataSourceName() string
- func (opts *MysqlDSNCreator) SetCharset(charset string) *MysqlDSNCreator
- func (opts *MysqlDSNCreator) SetLoc(loc string) *MysqlDSNCreator
- func (opts *MysqlDSNCreator) SetParseTime(parseTime bool) *MysqlDSNCreator
- func (opts *MysqlDSNCreator) SetReadTimeout(readTimeout time.Duration) *MysqlDSNCreator
- func (opts *MysqlDSNCreator) SetTimeout(timeout time.Duration) *MysqlDSNCreator
- func (opts *MysqlDSNCreator) SetWriteTimeout(writeTimeout time.Duration) *MysqlDSNCreator
- type TimeUtil
- type WaitTimeout
- type Watcher
Constants ¶
This section is empty.
Variables ¶
View Source
var (
DefTimeUtil = NewTimeUtil()
)
Functions ¶
func AppendBytes ¶ added in v0.0.2
func FormatTime ¶ added in v0.1.3
func MapToSlice ¶ added in v0.6.3
func MapToSlice[K comparable, V, T any](m map[K]V, transFunc func(K, V) (T, bool)) []T
func MapToSliceK ¶ added in v0.6.1
func MapToSliceK[K comparable, V any](m map[K]V) []K
func MapToSliceV ¶ added in v0.6.1
func MapToSliceV[K comparable, V any](m map[K]V) []V
func RandMapK ¶ added in v0.6.0
func RandMapK[K comparable, V any](m map[K]V, n int) []K
func RandMapV ¶ added in v0.6.0
func RandMapV[K comparable, V any](m map[K]V, n int) []V
func RandSliceWeightFunc ¶ added in v0.6.2
func RandSliceWeightFuncN ¶ added in v0.6.2
RandSliceWeightFuncN 根据权重随机选择 n 个元素,权重由 weightFunc 提供,可以重复选择同一个元素
func RandString ¶ added in v0.1.5
func SliceToMap ¶ added in v0.6.1
func SliceToMap[K comparable, V, T any](a []V, transFunc func(V) (K, T, bool)) map[K]T
func SliceToSlice ¶ added in v0.6.5
func TopMapN ¶ added in v0.6.0
func TopMapN[K comparable, V any](m map[K]V, n int, less func(V, V) bool) []V
func WaitExitSignal ¶ added in v0.4.0
func WaitExitSignal()
func WaitTimeoutFunc ¶ added in v0.2.1
func WriteBytes ¶ added in v0.0.2
Types ¶
type Duration ¶ added in v0.4.0
func (*Duration) MarshalJSON ¶ added in v0.4.0
func (*Duration) UnmarshalJSON ¶ added in v0.4.0
type MysqlDSNCreator ¶ added in v0.4.0
type MysqlDSNCreator struct {
// contains filtered or unexported fields
}
func NewMysqlDSNCreator ¶ added in v0.4.0
func NewMysqlDSNCreator(user, password, host, port, dbName string) *MysqlDSNCreator
func (*MysqlDSNCreator) DataSourceName ¶ added in v0.4.0
func (opts *MysqlDSNCreator) DataSourceName() string
func (*MysqlDSNCreator) SetCharset ¶ added in v0.4.0
func (opts *MysqlDSNCreator) SetCharset(charset string) *MysqlDSNCreator
func (*MysqlDSNCreator) SetLoc ¶ added in v0.4.0
func (opts *MysqlDSNCreator) SetLoc(loc string) *MysqlDSNCreator
func (*MysqlDSNCreator) SetParseTime ¶ added in v0.4.0
func (opts *MysqlDSNCreator) SetParseTime(parseTime bool) *MysqlDSNCreator
func (*MysqlDSNCreator) SetReadTimeout ¶ added in v0.4.0
func (opts *MysqlDSNCreator) SetReadTimeout(readTimeout time.Duration) *MysqlDSNCreator
func (*MysqlDSNCreator) SetTimeout ¶ added in v0.4.0
func (opts *MysqlDSNCreator) SetTimeout(timeout time.Duration) *MysqlDSNCreator
func (*MysqlDSNCreator) SetWriteTimeout ¶ added in v0.4.0
func (opts *MysqlDSNCreator) SetWriteTimeout(writeTimeout time.Duration) *MysqlDSNCreator
type TimeUtil ¶ added in v0.1.3
type TimeUtil struct {
// contains filtered or unexported fields
}
时间工具,在测试中,很多时候需要控制 time.Now() 产生的时间 例如:设置当前时间为 3天 后,用正常时间的 1/10 行进时间
func NewTimeUtil ¶ added in v0.1.3
func NewTimeUtil() *TimeUtil
type WaitTimeout ¶ added in v0.2.1
type WaitTimeout struct {
// contains filtered or unexported fields
}
WaitTimeout 带有超时的 WaitGroup,避免了 wg.Wait() 可能引起的 blocked forever,协程永远无法被释放
func NewWaitTimeout ¶ added in v0.2.1
func NewWaitTimeout() *WaitTimeout
NewWaitTimeout 必须使用 NewWaitTimeout 实例化 WaitTimeout
func (*WaitTimeout) Add ¶ added in v0.2.1
func (wt *WaitTimeout) Add(n int32) *WaitTimeout
func (*WaitTimeout) Done ¶ added in v0.2.1
func (wt *WaitTimeout) Done()
type Watcher ¶ added in v0.2.2
type Watcher struct {
// contains filtered or unexported fields
}
func NewWatcher ¶ added in v0.2.2
func NewWatcher() *Watcher
Click to show internal directories.
Click to hide internal directories.