Documentation ¶
Index ¶
- Constants
- Variables
- func AnyArrayToFloat64Array(arrInterface []interface{}) []float64
- func AnyArrayToInt64Array(arrInterface []interface{}) []int64
- func AnyArrayToStringArray(arrInterface []interface{}) []string
- func AnyToBool(v interface{}) bool
- func AnyToBoolArray(any interface{}) []bool
- func AnyToFloat64(value interface{}) float64
- func AnyToFloat64Array(any interface{}) []float64
- func AnyToInt64(value interface{}) int64
- func AnyToInt64Array(any interface{}) []int64
- func AnyToMapStringAny(content any) map[string]any
- func AnyToString(value interface{}) string
- func AnyToStringArray(any interface{}) []string
- func BytesToString(b []byte) string
- func CNFormatToTime(timeString string) time.Time
- func CanConvertToFloat32Loselessly(v float64) bool
- func CanConvertToInt32Loselessly(v float64) bool
- func CanConvertToInt64Loselessly(v float64) bool
- func CheckEmail(str string) bool
- func DayDiff(date1, date2 time.Time, loc *time.Location) int
- func EnvironmentVariables() map[string]string
- func FilterSlice[Element any](slice []Element, fn func(e Element) bool) (ret []Element)
- func FindFirstInSliceWhere[Element any](slice []Element, fn func(e Element) bool) int
- func FindFirstRefInSliceWhere[Element any](slice []Element, fn func(e Element) bool) *Element
- func FindInAnyMap(m AnyMap, keys ...interface{}) interface{}
- func FindInAnyMapWithKeys(m AnyMap, keys []interface{}) interface{}
- func FindInFloat64Array(slice []float64, item float64) int
- func FindInInt64Array(slice []int64, item int64) int
- func FindInSlice[Element comparable](slice []Element, item Element) int
- func FindInStrMap(m StrMap, keys ...interface{}) interface{}
- func FindInStrMapWithKeys(m StrMap, keys []interface{}) interface{}
- func FindInStrings(slice []string, item string) int
- func FindInSyncMap(m *sync.Map, keys ...interface{}) interface{}
- func FindInSyncMapWithKeys(m *sync.Map, keys []interface{}) interface{}
- func GenID(prefix string) string
- func GenPassword() string
- func GenUUID() string
- func GenerateFixedLengthRandomString(length uint8) string
- func GenerateFixedLengthUUID(length uint8) string
- func GenerateSnowflakeID() snowflake.ID
- func GetCNCurrentTime() time.Time
- func GetCNFormatCurrentTime() string
- func Hash(bs []byte) uint32
- func InitSnowflakeNode(index int64)
- func IsAlnumString(s string) bool
- func IsAlphaString(s string) bool
- func IsDateEqual(date1, date2 time.Time, loc *time.Location) bool
- func IsNumString(s string) bool
- func IsNumeric(value interface{}) bool
- func IsSliceEqual[Element comparable](slice1, slice2 []Element) bool
- func MapSlice[Element any, Return any](slice []Element, fn func(Element) Return) []Return
- func Max[Value Number](l, r Value) Value
- func MaxInt64(a, b int64) int64
- func MillisecondOfTime(t time.Time) int64
- func Min[Value Number](l, r Value) Value
- func MinInt64(a, b int64) int64
- func PanicIfNotNil(err error)
- func RemovePrefixKeys(data map[string]any, prefix string)
- func ReversedSlice[Element any](slice []Element) []Element
- func StringPToBytes(s *string) []byte
- func StringToBytes(s string) []byte
- func StringToChunks(s string, chunkSize int) []string
- func StringToInt64(value string) (int64, error)
- func StringWithCharset(length int, charset string) string
- func TimeInSnowflakeID(id snowflake.ID) time.Time
- func TimeInSnowflakeInt(id int64) time.Time
- func TimeToCNFormat(t time.Time) string
- type AnyMap
- type CustomStringConvertable
- type Number
- type Optional
- func FlatMapOptional[Wrapped any, Return any](opt Optional[Wrapped], fn func(Wrapped) Optional[Return]) Optional[Return]
- func MapOptional[Wrapped any, Return any](opt Optional[Wrapped], fn func(Wrapped) Return) Optional[Return]
- func NoneOptional[Wrapped any]() Optional[Wrapped]
- func OptionalWithPointer[Wrapped any](v *Wrapped) Optional[Wrapped]
- func SomeOptional[Wrapped any](v Wrapped) Optional[Wrapped]
- type RWLock
- type Range
- type Result
- func FlatMapResult[Success any, Failure error, NewSuccess any](result Result[Success, Failure], fn func(Success) Result[NewSuccess, Failure]) Result[NewSuccess, Failure]
- func MapResult[Success any, Failure error, NewSuccess any](result Result[Success, Failure], fn func(Success) NewSuccess) Result[NewSuccess, Failure]
- func ResultWithFailure[Success any, Failure error](e Failure) Result[Success, Failure]
- func ResultWithSuccess[Success any, Failure error](v Success) Result[Success, Failure]
- type Set
- type StrMap
- type TimeInDay
Constants ¶
const ( CNGMT = "+0800" // Time duration for one day. TimeDay = 24 * time.Hour )
const (
MaxSnowflakeNodeIndex = 1023
)
const TimeLayout = "2006-01-02 15:04:05"
Variables ¶
var (
CNTimeLocation *time.Location
)
Functions ¶
func AnyArrayToFloat64Array ¶
func AnyArrayToFloat64Array(arrInterface []interface{}) []float64
func AnyArrayToInt64Array ¶
func AnyArrayToInt64Array(arrInterface []interface{}) []int64
func AnyArrayToStringArray ¶
func AnyArrayToStringArray(arrInterface []interface{}) []string
func AnyToBoolArray ¶
func AnyToBoolArray(any interface{}) []bool
func AnyToFloat64 ¶
func AnyToFloat64(value interface{}) float64
func AnyToFloat64Array ¶
func AnyToFloat64Array(any interface{}) []float64
func AnyToInt64 ¶
func AnyToInt64(value interface{}) int64
func AnyToInt64Array ¶
func AnyToInt64Array(any interface{}) []int64
func AnyToMapStringAny ¶
AnyToMapStringAny 将 Content 转化为 Map<String>Any,使其序列化时按字典序排序
func AnyToString ¶
func AnyToString(value interface{}) string
func AnyToStringArray ¶
func AnyToStringArray(any interface{}) []string
func CNFormatToTime ¶
func CheckEmail ¶
func EnvironmentVariables ¶
func FilterSlice ¶
func FindFirstInSliceWhere ¶
func FindInAnyMap ¶
func FindInAnyMap(m AnyMap, keys ...interface{}) interface{}
func FindInAnyMapWithKeys ¶
func FindInAnyMapWithKeys(m AnyMap, keys []interface{}) interface{}
func FindInFloat64Array ¶
func FindInInt64Array ¶
func FindInSlice ¶
func FindInSlice[Element comparable](slice []Element, item Element) int
FindInStrings would return first index of `slice` if found `item`, or -1 for not.
func FindInStrMap ¶
func FindInStrMap(m StrMap, keys ...interface{}) interface{}
func FindInStrMapWithKeys ¶
func FindInStrMapWithKeys(m StrMap, keys []interface{}) interface{}
func FindInStrings ¶
FindInStrings would return first index of `slice` if found `item`, or -1 for not.
func FindInSyncMap ¶
func FindInSyncMapWithKeys ¶
func GenerateFixedLengthUUID ¶
GenerateFixedLengthUUID generates base32 uuid with the given length. the generated uuid consists of two parts:`timestampBase32String` and `randomBase32String` `timestampBase32String` is generated by base32-encoded millisecond timestamp, length is 8. `randomBase32String` is generated by base32-encoded random int64 which is generated by `math/rand` library. parameter `length` should be at least 8 if uniqueness need to be guaranteed in one millisecond.
func GetCNCurrentTime ¶
func GetCNFormatCurrentTime ¶
func GetCNFormatCurrentTime() string
func InitSnowflakeNode ¶
func InitSnowflakeNode(index int64)
InitSnowflakeNode 使用index初始化随机ID生成器,index需在[0,1023]之间.
func IsAlnumString ¶
func IsAlphaString ¶
func IsNumString ¶
func IsSliceEqual ¶
func IsSliceEqual[Element comparable](slice1, slice2 []Element) bool
func MillisecondOfTime ¶
func PanicIfNotNil ¶
func PanicIfNotNil(err error)
func RemovePrefixKeys ¶
RemovePrefixKeys 删除 Map 中指定前缀的 Key
func ReversedSlice ¶
func ReversedSlice[Element any](slice []Element) []Element
func StringPToBytes ¶
func StringToBytes ¶
StringToBytes 按[]byte的底层结构,转换字符串,len与cap皆为字符串的len
func StringToChunks ¶
StringToChunks split a string into string slices with element's size <= chunkSize Examples: StringToChunks("abcd", 1) => []string{"a", "b", "c", "d"} StringToChunks("abcd", 2) => []string{"ab", "cd"} StringToChunks("abcd", 3) => []string{"abc", "d"} stringToChunks("abcd", 4) => []string{"abcd"} stringToChunks("abcd", 5) => []string{"abcd"}
func StringToInt64 ¶
func StringWithCharset ¶
func TimeInSnowflakeInt ¶
func TimeToCNFormat ¶
Types ¶
type AnyMap ¶
type AnyMap = map[interface{}]interface{}
func AnyToAnyMap ¶
func AnyToAnyMap(value interface{}) AnyMap
type CustomStringConvertable ¶
type CustomStringConvertable interface {
String() string
}
type Optional ¶
type Optional[Wrapped any] struct { // contains filtered or unexported fields }
Optional is a type represents either a wrapped value or `nil`, the absence of a value.
func FlatMapOptional ¶
func MapOptional ¶
func NoneOptional ¶
func OptionalWithPointer ¶
Wrap nullable pointer as Optional, nil with NoneOptional, non-nil with SomeOptional.
func SomeOptional ¶
type Range ¶
type Range[Bound Number] struct { // contains filtered or unexported fields }
Range of any number `Bound`.
func NewClosedRange ¶
Range with [lower, upper].
func NewUpperOpenedRange ¶
Range with [lower, upper).
func (Range[Bound]) WithLowerOpened ¶
func (Range[Bound]) WithUpperOpened ¶
type Result ¶
A value that represents either a success or a failure, including an associated value in each case.
func FlatMapResult ¶
func ResultWithFailure ¶
func ResultWithSuccess ¶
type Set ¶
type Set[Element comparable] struct { // contains filtered or unexported fields }
An unordered collection of unique elements.
func NewSet ¶
func NewSet[Element comparable](values ...Element) Set[Element]
type StrMap ¶
type StrMap = map[string]interface{}
func AnyArrayToStrMap ¶
func AnyArrayToStrMap(mapInterface []interface{}) StrMap
func AnyToStrMap ¶
func AnyToStrMap(value interface{}) StrMap
func FlattenMap ¶
flatten map ,e.g map A
{ "foo":{ "bar":1 } }
map B = FlattenMap("",".",A)
{ "foo.bar":1 }
type TimeInDay ¶
func MakeTimeInDay ¶
func ParseTimeInDay ¶
ParseTimeInDay would parse TimeInDay from time string, e.g. 09 or 8:25 or 22:03:2.