utils

package
v0.0.42 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeOffset = 8 * 3600  //8 hour offset
	HalfOffset = 12 * 3600 //Half-day hourly offset
)

Variables

View Source
var ServerIP = ""

Functions

func AesDecrypt

func AesDecrypt(data []byte, key []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(data []byte, key []byte) ([]byte, error)

func Base64Decode

func Base64Decode(data string) string

func Base64Encode

func Base64Encode(data string) string

func Batch

func Batch[T any, V any](fn func(T) V, ts []T) []V

func BothExist

func BothExist[E comparable](es ...[]E) []E

BothExist 获取切片中共同存在的元素(交集)

func BothExistAny

func BothExistAny[E any, K comparable](es [][]E, fn func(e E) K) []E

BothExistAny 获取切片中共同存在的元素(交集)

func Complete

func Complete[E comparable](a []E, b []E) bool

Complete a和b去重后是否相等(忽略顺序)

func Contain

func Contain[E comparable](e E, es ...E) bool

Contain 是否包含

func Delete

func Delete[E any](es []E, index ...int) []E

Delete 删除切片元素, 支持负数删除倒数第几个

func DeleteAt

func DeleteAt[E any](es *[]E, index ...int) []E

DeleteAt 删除切片元素, 支持负数删除倒数第几个

func Distinct

func Distinct[T comparable](ts []T) []T

Distinct 去重

func DistinctAny

func DistinctAny[E any, K comparable](es []E, fn func(e E) K) []E

DistinctAny 去重

func DistinctAnyGetComparable

func DistinctAnyGetComparable[E any, K comparable](es []E, fn func(e E) K) []K

func Duplicate

func Duplicate[E comparable](es []E) bool

Duplicate 是否有重复的

func DuplicateAny

func DuplicateAny[E any, K comparable](es []E, fn func(e E) K) bool

DuplicateAny 是否有重复的

func Equal

func Equal[E comparable](a []E, b []E) bool

Equal 比较切片是否相对(包括元素顺序)

func Filter

func Filter[E, T any](es []E, fn func(e E) (T, bool)) []T

func GetCurDayHalfTimeFormat

func GetCurDayHalfTimeFormat() string

Get the formatted time at 12 o'clock of the day, the format is "2006-01-02_12-00-00"

func GetCurDayHalfTimestamp

func GetCurDayHalfTimestamp() int64

Get the timestamp at 12 o'clock on the day

func GetCurDayZeroTimeFormat

func GetCurDayZeroTimeFormat() string

Get the formatted time at 0 o'clock of the day, the format is "2006-01-02_00-00-00"

func GetCurDayZeroTimestamp

func GetCurDayZeroTimestamp() int64

Get the timestamp at 0 o'clock of the day

func GetCurrentTimestampByMill

func GetCurrentTimestampByMill() int64

Get the current timestamp by Mill

func GetCurrentTimestampByNano

func GetCurrentTimestampByNano() int64

Get the current timestamp by Nano

func GetCurrentTimestampBySecond

func GetCurrentTimestampBySecond() int64

Get the current timestamp by Second

func GetLocalIP

func GetLocalIP() (string, error)

func GetMsgID

func GetMsgID(sendID string) string

func GetSwitchFromOptions

func GetSwitchFromOptions(Options map[string]bool, key string) (result bool)

func GetTimeStampByFormat

func GetTimeStampByFormat(datetime string) string

func HasKey

func HasKey[K comparable, V any](m map[K]V, k K) bool

HasKey get whether the map contains key

func If

func If[T any](isa bool, a, b T) T

If true -> a, false -> b

func IndexAny

func IndexAny[E any, K comparable](e E, es []E, fn func(e E) K) int

IndexAny get the index of the element

func IndexOf

func IndexOf[E comparable](e E, es ...E) int

IndexOf get the index of the element

func InitMap

func InitMap[K comparable, V any](val *map[K]V)

func InitSlice

func InitSlice[T any](val *[]T)

func Keys

func Keys[K comparable, V any](kv map[K]V) []K

Keys get map keys

func Max

func Max[E Ordered](e ...E) E

Max get maximum value

func Md5

func Md5(s string, salt ...string) string

func Min

func Min[E Ordered](e ...E) E

Min get minimum value

func NotNilReplace

func NotNilReplace[T any](old, new_ *T)

NotNilReplace 当new_不为空时, 将old设置为new_

func Order

func Order[E comparable, T any](es []E, ts []T, fn func(t T) E) []T

Order 将ts按es排序

func OrderPtr

func OrderPtr[E comparable, T any](es []E, ts *[]T, fn func(t T) E) []T

func Paginate

func Paginate[E any](es []E, pageNumber int, showNumber int) []E

func SetSwitchFromOptions

func SetSwitchFromOptions(options map[string]bool, key string, value bool)

func Single

func Single[E comparable](a, b []E) []E

Single a中存在,b中不存在 或 b中存在,a中不存在

func Slice

func Slice[E any, T any](es []E, fn func(e E) T) []T

Slice 批量转换切片类型

func SliceAnySub

func SliceAnySub[E any, T comparable](a, b []E, fn func(t E) T) []E

SliceAnySub a中存在,b中不存在 (a-b) fn 返回的是uuid

func SliceSet

func SliceSet[E comparable](es []E) map[E]struct{}

SliceSet slice to map[E]struct{}

func SliceSetAny

func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{}

SliceSetAny slice to map[K]struct{}

func SliceSub

func SliceSub[E comparable](a, b []E) []E

SliceSub a中存在,b中不存在 (a-b)

func SliceSubAny

func SliceSubAny[E comparable, T any](a []E, b []T, fn func(t T) E) []E

SliceSubAny a中存在,b中不存在 (a-b)

func SliceToMap

func SliceToMap[E any, K comparable](es []E, fn func(e E) K) map[K]E

SliceToMap slice to map

func SliceToMapAny

func SliceToMapAny[E any, K comparable, V any](es []E, fn func(e E) (K, V)) map[K]V

SliceToMapAny slice to map (自定义类型)

func SliceToMapOkAny

func SliceToMapOkAny[E any, K comparable, V any](es []E, fn func(e E) (K, V, bool)) map[K]V

SliceToMapOkAny slice to map (自定义类型, 筛选)

func Sort

func Sort[E Ordered](es []E, asc bool) []E

Sort basic type sorting

func SortAny

func SortAny[E any](es []E, fn func(a, b E) bool)

SortAny custom sort method

func StructFieldNotNilReplace added in v0.0.17

func StructFieldNotNilReplace(dest, src any)

func StructToJsonString

func StructToJsonString(param any) string

func TimeStringFormatTimeUnix

func TimeStringFormatTimeUnix(timeFormat string, timeSrc string) int64

func TimeStringToTime

func TimeStringToTime(timeString string) (time.Time, error)

func TimeToString

func TimeToString(t time.Time) string

func ToPtr

func ToPtr[T any](t T) *T

func UniqueJoin

func UniqueJoin(s ...string) string

func UnixMillSecondToTime

func UnixMillSecondToTime(millSecond int64) time.Time

func UnixNanoSecondToTime

func UnixNanoSecondToTime(nanoSecond int64) time.Time

Convert nano timestamp to time.Time type

func UnixSecondToTime

func UnixSecondToTime(second int64) time.Time

Convert timestamp to time.Time type

func Unwrap

func Unwrap(err error) error

func Values

func Values[K comparable, V any](kv map[K]V) []V

Values get map values

Types

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
}

Ordered types that can be sorted

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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