Documentation ¶
Index ¶
- Constants
- Variables
- func AnyPtr[T any](s T) *T
- func ApplyOptions[T any](opts ...OptionExtender) (t *T)
- func Catch(fn any) (isPanic bool, err error)
- func CheckIfAny(fnList ...func() error) error
- func ClientIP() (ip string)
- func CloseAnyway[T any](closer T)
- func ComparableToSortable[T comparable](s T) (d any)
- func CryptoRandom(b []byte) (n int, err error)
- func CryptoRandomBytes(size int) ([]byte, error)
- func CryptoRandomLetterAndNumber(n int) (string, error)
- func CryptoRandomNumbers(n int) (string, error)
- func DecimalPlaces(num float64) int
- func EmbedsType(i any, e reflect.Type) bool
- func ErrIgnore(src error, ignored ...error) (dst error)
- func FlushAnyway[T any](flusher T)
- func FuzzyKeyword(keyword string) []string
- func GetCaller(maximumCallerDepth int, opts ...OptionExtender) (frame *runtime.Frame)
- func GetCtxAny[T any](ctx context.Context, key string, args ...T) (val T)
- func GetFieldByTag(data any, tag, key string) (r reflect.Value, e error)
- func GetFieldByTagWithKeys(data any, tag string, keys []string) (r reflect.Value, e error)
- func GetFieldTagValue(data any, tag string, pattern *regexp.Regexp) (tagValue string, e error)
- func GetFuncName(fn any) string
- func GetGormColumnValue(data any, column string) (columnVal reflect.Value, ok bool)
- func GetTime(timestampMs int64) time.Time
- func GetTimeStamp(t time.Time) int64
- func HostIPInDocker() (ip string)
- func IfAny(fnList ...func() bool)
- func IgnoreEnumStringCase() enumStringOptFn
- func IndirectType(s reflect.Type) (d reflect.Type)
- func IndirectValue(s reflect.Value) (d reflect.Value)
- func IntNarrow(num int) (result any)
- func IsBlank(object any) bool
- func IsChannelClosed[T any](ch <-chan T) (data T, ok bool)
- func IsInRange[T constraint.Sortable](num, min, max T) bool
- func IsStrBlank(s string) bool
- func IsStrNotBlank(s string) bool
- func IsStrPtrBlank(s *string) bool
- func IsStrPtrNotBlank(s *string) bool
- func IsValidTimestamp(timeMS int64) bool
- func LookupByFuzzyKeyword[T any, F lookupByFuzzyKeywordFuncType[T]](lookup F, keyword string) (v T)
- func LoopWithInterval(ctx context.Context, interval time.Duration, fn func() bool, ...) (err error)
- func MapKeys[T comparable, K any](m map[T]K) (keys []T)
- func MapMerge[T comparable, K any](a, b map[T]K) (r map[T]K)
- func MapSliceToMap[T comparable, K any](s []map[T]K) (d map[T]K)
- func MapValues[T comparable, K any](m map[T]K) (vals []K)
- func MapValuesByKeys[T comparable, K any, TS ~[]T](m map[T]K, keys TS) (vals []K)
- func Max[T constraint.Sortable](arr ...T) T
- func Min[T constraint.Sortable](arr ...T) T
- func Must[T any](out T, err error) T
- func MustJsonMarshal(s any) []byte
- func MustJsonMarshalString(s any) string
- func MustJsonUnmarshal[T any](s []byte) (t *T)
- func MustOk[T any](out T, ok bool) T
- func MustSuccess(err error)
- func NewSafeRand(seed int64) *rand.Rand
- func NextJitterIntervalFunc(base, max time.Duration, ratio, exp float64, symmetric bool) func() time.Duration
- func NginxID() string
- func ParseTag(data any, opts ...OptionExtender) (err error)
- func ParseVariadicFuncResult[T any](rs []reflect.Value, idx int) (t T)
- func Random(b []byte, seed int64) (n int, err error)
- func RandomLetterAndNumber(n int) string
- func RandomNumbers(n int) string
- func SetCtxAny[T any](ctx context.Context, key string, val T) context.Context
- func ShortUUID() string
- func SliceConvert(src any, dstType reflect.Type) any
- func SliceMapping[T, K any](s []T, mapFn func(t T) K) (d []K)
- func SliceRemove[T any, TS ~[]T](s TS, filter func(t T) bool) (d TS)
- func SliceReverse[T any, TS ~[]T](s TS)
- func SliceToMap[K comparable, V any](s []V, groupFn func(v V) K) (d map[K]V)
- func Sort[E any](data []E, cmp func(e1, e2 E) int)
- func SortStable[E any](data []E, cmp func(e1, e2 E) int)
- func SortableToGeneric[T, K constraint.Sortable](s T) (d K)
- func Timeout(timeout time.Duration, opts ...OptionExtender) bool
- func TravelCtx(child context.Context, fn func(ctx context.Context) bool)
- func TraverseValue(data any, indirect bool, ...)
- func ULID() string
- func UUID() string
- func UUID20() string
- func UUID22() string
- func UUID_() string
- func UintNarrow(num uint) (result any)
- func Unmarshal(s, d any, tag unmarshalType) (err error)
- func UnsafeBytesToString(b []byte) string
- func UnsafeStringToBytes(s string) []byte
- func WrapFunc(fn any) func(...any)
- func WrapFunc1[T any](fn any) func(...any) T
- func WrapFunc2[T1, T2 any](fn any) func(...any) (T1, T2)
- func WrapFunc3[T1, T2, T3 any](fn any) func(...any) (T1, T2, T3)
- func WrapFunc4[T1, T2, T3, T4 any](fn any) func(...any) (T1, T2, T3, T4)
- func WrapFunc5[T1, T2, T3, T4, T5 any](fn any) func(...any) (T1, T2, T3, T4, T5)
- func WrapFunc6[T1, T2, T3, T4, T5, T6 any](fn any) func(...any) (T1, T2, T3, T4, T5, T6)
- func WrapFunc7[T1, T2, T3, T4, T5, T6, T7 any](fn any) func(...any) (T1, T2, T3, T4, T5, T6, T7)
- func WrapFuncAny(fn any) func(...any) []any
- type Enumerable
- type Error
- type Heap
- type InvalidUnmarshalError
- type JsonStringify
- type OptionExtender
- type OptionFunc
- func LoopJitterInterval(base, max time.Duration, ratio, exp float64, symmetric bool) OptionFunc[loopWithIntervalOption]
- func LoopMaxTimes(maxTimes uint) OptionFunc[loopWithIntervalOption]
- func ParseTagName(tag string) OptionFunc[parseTagOption]
- func ParseTagOverwrite(overwrite bool) OptionFunc[parseTagOption]
- func ParseTagUnmarshalType(unmarshalTag unmarshalType) OptionFunc[parseTagOption]
- func PoolableEvictFunc[T any](fn func(obj T) bool) OptionFunc[poolableOption[T]]
- func SkipGlobs(patterns ...string) OptionFunc[getCallerOption]
- func SkipKnownDepth(minimumCallerDepth int) OptionFunc[getCallerOption]
- func SkipRegexps(patterns ...string) OptionFunc[getCallerOption]
- func TimeoutWg(wg *sync.WaitGroup) OptionFunc[timeoutOption]
- type Poolable
- type Set
- func (s *Set[T]) Clone() (r *Set[T])
- func (s *Set[T]) Contains(val T) bool
- func (s *Set[T]) Equals(o *Set[T]) bool
- func (s *Set[T]) Filter(fn func(T) bool) *Set[T]
- func (s *Set[T]) Insert(val ...T) *Set[T]
- func (s *Set[T]) IntersectsWith(set *Set[T]) bool
- func (s *Set[T]) IsSubsetOf(set *Set[T]) bool
- func (s *Set[T]) Items() []T
- func (s *Set[T]) Reject(fn func(T) bool) *Set[T]
- func (s *Set[T]) Remove(val ...T) *Set[T]
- func (s *Set[T]) Size() int
Constants ¶
const ( UnmarshalTypeJson unmarshalType = "json" UnmarshalTypeYaml unmarshalType = "yaml" UnmarshalTypeToml unmarshalType = "toml" )
Variables ¶
var ( // BytesBufferPool 64 is bytes.Buffer smallBufferSize, which is an initial allocation minimal capacity. BytesBufferPool = NewPool( func() *bytes.Buffer { return bytes.NewBuffer(make([]byte, 0, 64)) }, PoolableEvictFunc(poolBytesBufferEvict), ) BytesPool = NewPool( func() poolBytes { return make([]byte, 0, 64) }, PoolableEvictFunc(poolBytesEvict), ) )
var (
ErrEmptyArray = errors.New("empty array")
)
var (
ErrOutOfRange = errors.New("out of range")
)
var LocalIP = &localIP{ str: ClientIP(), bytes: func() []byte { reverse := func(bs []byte) { i, j := 0, len(bs)-1 for i < j { bs[i], bs[j] = bs[j], bs[i] i++ j-- } } if ipAddr := ClientIP(); ipAddr != "" { realIP := []byte("000000000000") idx := 0 for i := len(ipAddr) - 1; i >= 0; i-- { c := ipAddr[i] if c == '.' { idx = (((idx - 1) / 3) + 1) * 3 continue } realIP[idx] = c idx++ } reverse(realIP) return realIP } return []byte("000000000000") }(), }
Functions ¶
func ApplyOptions ¶
func ApplyOptions[T any](opts ...OptionExtender) (t *T)
func CheckIfAny ¶
func CloseAnyway ¶
func CloseAnyway[T any](closer T)
func ComparableToSortable ¶
func ComparableToSortable[T comparable](s T) (d any)
ComparableToSortable convert generic type to sortable type
func CryptoRandom ¶
func CryptoRandomBytes ¶
func CryptoRandomNumbers ¶
func DecimalPlaces ¶
func EmbedsType ¶
EmbedsType Returns true if t embeds e or if any of the types embedded by t embed e. Forked from go.uber.org/dig@v1.16.1/inout.embedsType
func FlushAnyway ¶
func FlushAnyway[T any](flusher T)
func FuzzyKeyword ¶
func GetCaller ¶
func GetCaller(maximumCallerDepth int, opts ...OptionExtender) (frame *runtime.Frame)
GetCaller retrieves the name after stack skip
func GetFieldByTagWithKeys ¶
func GetFieldTagValue ¶
func GetFuncName ¶
func GetGormColumnValue ¶
func HostIPInDocker ¶
func HostIPInDocker() (ip string)
func IgnoreEnumStringCase ¶
func IgnoreEnumStringCase() enumStringOptFn
func IsBlank ¶
IsBlank gets whether the specified object is considered empty or not. fork from: github.com/stretchr/testify@v1.8.0/assert/assertions.go
func IsChannelClosed ¶
func IsInRange ¶
func IsInRange[T constraint.Sortable](num, min, max T) bool
func IsStrBlank ¶
func IsStrNotBlank ¶
func IsStrPtrBlank ¶
func IsStrPtrNotBlank ¶
func IsValidTimestamp ¶
IsValidTimestamp 返回 false 表示无法对毫秒时间戳和 time.Time 进行精确转换
func LookupByFuzzyKeyword ¶
func LoopWithInterval ¶
func LoopWithInterval(ctx context.Context, interval time.Duration, fn func() bool, opts ...OptionExtender) (err error)
LoopWithInterval Deprecated, try github.com/rican7/retry.Retry instead
func MapKeys ¶
func MapKeys[T comparable, K any](m map[T]K) (keys []T)
func MapMerge ¶
func MapMerge[T comparable, K any](a, b map[T]K) (r map[T]K)
func MapSliceToMap ¶
func MapSliceToMap[T comparable, K any](s []map[T]K) (d map[T]K)
func MapValues ¶
func MapValues[T comparable, K any](m map[T]K) (vals []K)
func MapValuesByKeys ¶
func MapValuesByKeys[T comparable, K any, TS ~[]T](m map[T]K, keys TS) (vals []K)
func Max ¶
func Max[T constraint.Sortable](arr ...T) T
func Min ¶
func Min[T constraint.Sortable](arr ...T) T
func MustJsonMarshal ¶
func MustJsonMarshalString ¶
func MustJsonUnmarshal ¶
func MustSuccess ¶
func MustSuccess(err error)
func NewSafeRand ¶
func NextJitterIntervalFunc ¶
func NextJitterIntervalFunc(base, max time.Duration, ratio, exp float64, symmetric bool) func() time.Duration
NextJitterIntervalFunc generate a jitter and exponential power duration, inspired by net/http.(*Server).Shutdown
func ParseTag ¶
func ParseTag(data any, opts ...OptionExtender) (err error)
func ParseVariadicFuncResult ¶
func RandomLetterAndNumber ¶
func RandomNumbers ¶
func SliceConvert ¶
SliceConvert >= go1.18 recommend to use SliceMapping
func SliceMapping ¶
func SliceMapping[T, K any](s []T, mapFn func(t T) K) (d []K)
SliceMapping Mapping slice convert go1.18 version
func SliceRemove ¶
func SliceReverse ¶
func SliceReverse[T any, TS ~[]T](s TS)
func SliceToMap ¶
func SliceToMap[K comparable, V any](s []V, groupFn func(v V) K) (d map[K]V)
func SortStable ¶
func SortableToGeneric ¶
func SortableToGeneric[T, K constraint.Sortable](s T) (d K)
SortableToGeneric convert sortable type to generic type
func TraverseValue ¶
func UintNarrow ¶
func UnsafeBytesToString ¶
UnsafeBytesToString converts byte slice to string without a memory allocation. Fork from github.com/gin-gonic/gin@v1.7.7/internal/bytesconv/bytesconv.go
func UnsafeStringToBytes ¶
UnsafeStringToBytes converts string to byte slice without a memory allocation. Fork from github.com/gin-gonic/gin@v1.7.7/internal/bytesconv/bytesconv.go
func WrapFunc2 ¶
WrapFunc2 wrap a function with any number inputs and 2 generic type return, return nothing if function has 0 outputs return T1 if function only has 1 output return function first output and last output if function has more than 2 outputs
func WrapFuncAny ¶
Types ¶
type Enumerable ¶
type Enumerable[T comparable, TS ~[]T] interface { Enum(s string) TS String(k any) string IsValid(t T) bool }
func NewEnumString ¶
func NewEnumString[T comparable, TS ~[]T](mapping map[T]string, opts ...OptionExtender) Enumerable[T, TS]
type Heap ¶
type Heap[E any] struct { // contains filtered or unexported fields }
Heap base on generics to build a heap tree for any type
func (*Heap[E]) Pop ¶
func (h *Heap[E]) Pop() E
Pop removes and returns the minimum element (according to Less) from the heap. The complexity is O(log n) where n = h.Len(). Pop is equivalent to Remove(h, 0).
type InvalidUnmarshalError ¶
An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
type JsonStringify ¶
type JsonStringify[T any] struct { Value T }
JsonStringify for k8s ConfigMap, Secret
func (*JsonStringify[T]) MarshalJSON ¶
func (j *JsonStringify[T]) MarshalJSON() (output []byte, err error)
func (*JsonStringify[T]) UnmarshalJSON ¶
func (j *JsonStringify[T]) UnmarshalJSON(input []byte) (err error)
type OptionExtender ¶
type OptionExtender interface {
// contains filtered or unexported methods
}
type OptionFunc ¶
type OptionFunc[T any] func(*T)
func LoopJitterInterval ¶
func LoopJitterInterval(base, max time.Duration, ratio, exp float64, symmetric bool) OptionFunc[loopWithIntervalOption]
LoopJitterInterval Deprecated, try github.com/rican7/retry.Retry instead
func LoopMaxTimes ¶
func LoopMaxTimes(maxTimes uint) OptionFunc[loopWithIntervalOption]
LoopMaxTimes Deprecated, try github.com/rican7/retry.Retry instead
func ParseTagName ¶
func ParseTagName(tag string) OptionFunc[parseTagOption]
func ParseTagOverwrite ¶
func ParseTagOverwrite(overwrite bool) OptionFunc[parseTagOption]
func ParseTagUnmarshalType ¶
func ParseTagUnmarshalType(unmarshalTag unmarshalType) OptionFunc[parseTagOption]
func PoolableEvictFunc ¶
func PoolableEvictFunc[T any](fn func(obj T) bool) OptionFunc[poolableOption[T]]
func SkipGlobs ¶
func SkipGlobs(patterns ...string) OptionFunc[getCallerOption]
func SkipKnownDepth ¶
func SkipKnownDepth(minimumCallerDepth int) OptionFunc[getCallerOption]
func SkipRegexps ¶
func SkipRegexps(patterns ...string) OptionFunc[getCallerOption]
func TimeoutWg ¶
func TimeoutWg(wg *sync.WaitGroup) OptionFunc[timeoutOption]
type Poolable ¶
func NewPool ¶
func NewPool[T any](newFn func() T, opts ...OptionExtender) Poolable[T]
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
func NewSet ¶
func NewSet[T comparable](arr ...T) (s *Set[T])
func (*Set[T]) IntersectsWith ¶
func (*Set[T]) IsSubsetOf ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package clone provides functions to deep clone any Go data.
|
Package clone provides functions to deep clone any Go data. |
Package sqlparser fork from github.com/longbridgeapp/sqlparser@v0.3.1
|
Package sqlparser fork from github.com/longbridgeapp/sqlparser@v0.3.1 |