glib

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MulanPSL-2.0 Imports: 24 Imported by: 1

README

gsf-lib

gsf 基本类库

Documentation

Index

Constants

View Source
const (
	RandStrNumberMask    = 0x01
	RandStrUpperCaseMask = 0x02
	RandStrLowerCaseMask = 0x04
)
View Source
const (
	TimeFormatDateTime       = "2006-01-02 15:04:05"
	TimeFormatDate           = "2006-01-02"
	TimeFormatDateYearMonth  = "2006-01"
	TimeFormatTime           = "15:04:05"
	TimeFormatTimeHourMinute = "15:04"
	TimeFormatANSIC          = time.ANSIC       // "Mon Jan _2 15:04:05 2006"
	TimeFormatUnixDate       = time.UnixDate    // "Mon Jan _2 15:04:05 MST 2006"
	TimeFormatRubyDate       = time.RubyDate    // "Mon Jan 02 15:04:05 -0700 2006"
	TimeFormatRFC822         = time.RFC822      // "02 Jan 06 15:04 MST"
	TimeFormatRFC822Z        = time.RFC822Z     // "02 Jan 06 15:04 -0700"
	TimeFormatRFC850         = time.RFC850      // "Monday, 02-Jan-06 15:04:05 MST"
	TimeFormatRFC1123        = time.RFC1123     // "Mon, 02 Jan 2006 15:04:05 MST"
	TimeFormatRFC1123Z       = time.RFC1123Z    // "Mon, 02 Jan 2006 15:04:05 -0700"
	TimeFormatRFC3339        = time.RFC3339     // "2006-01-02T15:04:05Z07:00"
	TimeFormatRFC3339Nano    = time.RFC3339Nano // "2006-01-02T15:04:05.999999999Z07:00"
	TimeFormatKitchen        = time.Kitchen     // "3:04PM"
)
View Source
const (
	TimeClearNSecondMask = 0x01
	TimeClearSecondMask  = 0x02
	TimeClearMinuteMask  = 0x04
	TimeClearHourMask    = 0x08

	TimeClearSecond = TimeClearNSecondMask
	TimeClearMinute = TimeClearSecondMask | TimeClearSecond
	TimeClearHour   = TimeClearMinuteMask | TimeClearMinute
	TimeClearTime   = TimeClearHourMask | TimeClearHour
)

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(ciphertext []byte, key []byte, iv []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error)

func BitCount

func BitCount[V constraints.Unsigned](v V) int

func Copy

func Copy(dst, src interface{}) error

func FileExist

func FileExist(path string) error

func FilesExist

func FilesExist(path ...string) error

func FloatToString

func FloatToString[R constraints.Float](v R, prec int) string

func GetClientIp

func GetClientIp(r *http.Request) string

GetClientIp 获取客户端 ip 地址

func IntegerToString

func IntegerToString[R constraints.Integer](v R) string

func Ip2Long

func Ip2Long(ipStr string) uint32

func IsPublicIP

func IsPublicIP(IP net.IP) bool

IsPublicIP 是否是外网 ip

func JoinFloat

func JoinFloat[T constraints.Float](s []T, sep string, prec int) string

JoinFloat join 浮点型

func JoinInt

func JoinInt[T constraints.Signed](s []T, sep string) string

JoinInt join 有符号整形

func JoinUint

func JoinUint[T constraints.Unsigned](s []T, sep string) string

JoinUint join 无符号整形

func Map2Slice

func Map2Slice[T, R any, K constraints.Ordered](s map[K]T, fn func(k K, v T) R) []R

Map2Slice map 转 切片

func Map2SliceFilter

func Map2SliceFilter[T, R any, K constraints.Ordered](val map[K]T, get func(T) (R, bool)) []R

Map2SliceFilter map 转 切片, 并过滤对应数据

func MapForEach

func MapForEach[K constraints.Ordered, T any](val map[K]T, handle func(K) error) error

func MapKeys

func MapKeys[K constraints.Ordered, V any](m map[K]V) []K

MapKeys 获取 keys

func MapMerge added in v0.1.6

func MapMerge[K constraints.Ordered, V any](maps ...map[K]V) map[K]V

MapMerge 多个 map merge

func MapValues

func MapValues[K constraints.Ordered, V any](m map[K]V) []V

MapValues 获取 values

func Md5

func Md5(str string) string

Md5 生成32位MD5摘要

func NetLong2ip

func NetLong2ip(ip uint32) string

NetLong2ip 获得 ip 地址

func ParseGzip

func ParseGzip(data []byte) ([]byte, error)

func RandInt

func RandInt(min, max int) int

RandInt 生成范围内的 int

func RandString

func RandString(length int, chars string, mod uint8) string

RandString 生成随机字符串

func RandStringEx

func RandStringEx(length int) string

func Slice2Map

func Slice2Map[E any, K constraints.Ordered](s []E, fn func(v *E) K) map[K]*E

Slice2Map 切片 转 map

func Slice2MapEx

func Slice2MapEx[T, V any, K constraints.Ordered](s []T, get func(*T) (K, V)) map[K]V

Slice2MapEx 切片 转 map

func Slice2MapExFilter

func Slice2MapExFilter[T, V any, K constraints.Ordered](s []T, get func(*T) (K, V, bool)) map[K]V

Slice2MapExFilter 切片 转 map, 并过滤对应数据

func Slice2MapFilter

func Slice2MapFilter[E any, K constraints.Ordered](s []E, fn func(v *E) (K, bool)) map[K]*E

Slice2MapFilter 切片 转 map, 并过滤对应数据

func Slice2Slice

func Slice2Slice[T, R any](arr []T, get func(*T) R) []R

Slice2Slice 切片 转 切片

func Slice2SliceFilter

func Slice2SliceFilter[T, R any](arr []T, get func(*T) (R, bool)) []R

Slice2SliceFilter 切片 转 切片, 并过滤对应数据

func SliceDifference

func SliceDifference[E constraints.Ordered](sliceList ...[]E) []E

SliceDifference 切片差集

func SliceDifferenceEx added in v0.2.0

func SliceDifferenceEx[K constraints.Ordered, E any](key func(*E) K, sliceList ...[]E) []*E

SliceDifferenceEx 切片差集

func SliceForEach

func SliceForEach[T any](arr []T, handle func(T) bool) bool

SliceForEach 切片遍历

func SliceForEachIdx

func SliceForEachIdx(l int, handle func(i int) bool) bool

SliceForEachIdx 切片遍历

func SliceIntersect

func SliceIntersect[E constraints.Ordered](sliceList ...[]E) []E

SliceIntersect 切片交集

func SliceIntersectEx added in v0.2.0

func SliceIntersectEx[K constraints.Ordered, E any](key func(*E) K, sliceList ...[]E) []*E

SliceIntersectEx 切片交集

func SliceSortAsc

func SliceSortAsc[T constraints.Ordered](v []T) []T

SliceSortAsc 切片排序(正序)

func SliceSortDesc

func SliceSortDesc[T constraints.Ordered](v []T) []T

SliceSortDesc 切片排序(倒序)

func SliceUnion

func SliceUnion[E constraints.Ordered](sliceList ...[]E) []E

SliceUnion 切片并集

func SliceUnionEx added in v0.2.0

func SliceUnionEx[E any, K constraints.Ordered](key func(*E) K, sliceList ...[]E) []*E

SliceUnionEx 切片并集

func SliceUnique

func SliceUnique[E constraints.Ordered](v []E) []E

SliceUnique 切片去重

func SplitFloat

func SplitFloat[T constraints.Float](s, sep string) ([]T, error)

SplitFloat split 切割 float

func SplitInt

func SplitInt[T constraints.Signed](s, sep string) ([]T, error)

SplitInt split 切割 int

func SplitSlice

func SplitSlice(v SplitSliceData, sHandle func(b, e int) error) error

SplitSlice split 切割 slice

func SplitSliceEx

func SplitSliceEx(v SplitSliceData, sHandle func(b, e int) error, eHandle func(i int) error) error

SplitSliceEx split 切割 slice

func SplitSliceTmp added in v0.1.3

func SplitSliceTmp[T any](v []T, cHandle func(a, b *T) bool, sHandle func(b, e int) error) error

SplitSliceTmp split 切割 slice

func SplitSliceTmpEx added in v0.1.3

func SplitSliceTmpEx[T any](v []T, cHandle func(a, b *T) bool, sHandle func(b, e int) error, eHandle func(i int) error) error

SplitSliceTmpEx split 切割 slice

func SplitUint

func SplitUint[T constraints.Unsigned](s, sep string) ([]T, error)

SplitUint split 切割 uint

func StringMerge

func StringMerge(str ...string) string

func StringToFloat

func StringToFloat(v string) float64

func StringToInteger

func StringToInteger(v string) int

func SubStr

func SubStr(str string, start int, end int) string

SubStr 获取子字符串

func TimeClearZero added in v0.1.3

func TimeClearZero(v time.Time, mask uint16) time.Time

func TimeFormatInLocation

func TimeFormatInLocation(tm time.Time, layout string) string

func TimeIsLeapYear added in v0.1.3

func TimeIsLeapYear(year int) bool

func TimeLatelyMonthDay added in v0.1.3

func TimeLatelyMonthDay(t time.Time, dd int, tl TimeLately, e bool) time.Time

TimeLatelyMonthDay 获取最近一个月的指定日的日期, day 值为 -1 时候表示最后一天

func TimeLatelyNMonthDay added in v0.1.6

func TimeLatelyNMonthDay(t time.Time, dd int, n uint, tl TimeLately, e bool) time.Time

TimeLatelyNMonthDay 获取最近 n 个月的指定日的日期, day 值为 -1 时候表示最后一天

func TimeLatelyNWeekDay added in v0.1.6

func TimeLatelyNWeekDay(t time.Time, w time.Weekday, n uint, tl TimeLately, e bool) time.Time

TimeLatelyNWeekDay 获取最近 n 个周的指定周的日期, e 只有在 tl 值为 TimeLatelyBefore 和 TimeLatelyAfter 有效。

func TimeLatelyWeekDay added in v0.1.3

func TimeLatelyWeekDay(t time.Time, w time.Weekday, tl TimeLately, e bool) time.Time

TimeLatelyWeekDay 获取最近一个周的指定周的日期, e 只有在 tl 值为 TimeLatelyBefore 和 TimeLatelyAfter 有效。

func TimeMonthDays added in v0.1.3

func TimeMonthDays(year int, month time.Month) int

func TimeMonthDaysEx added in v0.1.6

func TimeMonthDaysEx(t time.Time) int

func TimeParseInLocation

func TimeParseInLocation(tm, layout string) (time.Time, error)

func TimeThisMonthDay added in v0.1.6

func TimeThisMonthDay(t time.Time, dd int) time.Time

TimeThisMonthDay 获取本月的指定周的日期

func TimeThisWeekDay added in v0.1.6

func TimeThisWeekDay(t time.Time, w time.Weekday) time.Time

TimeThisWeekDay 获取本一个周的指定周的日期

func ToFloat

func ToFloat(val interface{}) float64

func ToInt

func ToInt(val interface{}) int

func ToString

func ToString(val interface{}, limit ...int) string

func VersionCompare

func VersionCompare(version1, version2, operator string) bool

版本对比

Types

type EmptyStruct

type EmptyStruct struct{}

type JsonRawByte added in v0.1.4

type JsonRawByte []byte

func (JsonRawByte) MarshalJSON added in v0.1.4

func (v JsonRawByte) MarshalJSON() ([]byte, error)

func (*JsonRawByte) Set added in v0.1.4

func (v *JsonRawByte) Set(val string)

func (*JsonRawByte) String added in v0.1.4

func (v *JsonRawByte) String() string

func (*JsonRawByte) UnmarshalJSON added in v0.1.4

func (v *JsonRawByte) UnmarshalJSON(bytes []byte) error

type JsonRawMarshalByte added in v0.1.4

type JsonRawMarshalByte []byte

func (JsonRawMarshalByte) MarshalJSON added in v0.1.4

func (v JsonRawMarshalByte) MarshalJSON() ([]byte, error)

func (*JsonRawMarshalByte) Set added in v0.1.4

func (v *JsonRawMarshalByte) Set(val string)

type JsonRawMarshalString added in v0.1.4

type JsonRawMarshalString string

func (JsonRawMarshalString) MarshalJSON added in v0.1.4

func (v JsonRawMarshalString) MarshalJSON() ([]byte, error)

type JsonRawString added in v0.1.4

type JsonRawString string

func (JsonRawString) MarshalJSON added in v0.1.4

func (v JsonRawString) MarshalJSON() ([]byte, error)

func (*JsonRawString) UnmarshalJSON added in v0.1.4

func (v *JsonRawString) UnmarshalJSON(bytes []byte) error

type JsonRawUnmarshalByte added in v0.1.4

type JsonRawUnmarshalByte []byte

func (*JsonRawUnmarshalByte) String added in v0.1.4

func (v *JsonRawUnmarshalByte) String() string

func (*JsonRawUnmarshalByte) UnmarshalJSON added in v0.1.4

func (v *JsonRawUnmarshalByte) UnmarshalJSON(bytes []byte) error

type JsonRawUnmarshalString

type JsonRawUnmarshalString string

func (*JsonRawUnmarshalString) UnmarshalJSON

func (s *JsonRawUnmarshalString) UnmarshalJSON(bytes []byte) error

type Map4Any

type Map4Any map[string]interface{}

type ParallelErrorHandle added in v0.1.3

type ParallelErrorHandle func(err error)

type ParallelFailType added in v0.1.3

type ParallelFailType uint8
const (
	ParallelFailTypeAll ParallelFailType = 1
	ParallelFailTypeOne ParallelFailType = 2
)

type ParallelFunc added in v0.1.3

type ParallelFunc func() error

type ParallelHandle added in v0.1.3

type ParallelHandle func(cancelCtx context.Context) error

func ParallelGetFunc added in v0.1.3

func ParallelGetFunc(handle ParallelFunc) ParallelHandle

func ParallelGetHttpRequest added in v0.1.3

func ParallelGetHttpRequest(client *http.Client, newReqHandler ParallelHttpNewRequest, reqFormatHandler ParallelHttpResponseFormat) ParallelHandle

type ParallelHttpNewRequest added in v0.1.3

type ParallelHttpNewRequest func(cancelCtx context.Context) (*http.Request, error)

type ParallelHttpResponseFormat added in v0.1.3

type ParallelHttpResponseFormat func(io.ReadCloser) error

type ParallelMgt added in v0.1.3

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

func (*ParallelMgt) AddFunc added in v0.1.3

func (r *ParallelMgt) AddFunc(handle ParallelFunc) int

func (*ParallelMgt) AddHandles added in v0.1.3

func (r *ParallelMgt) AddHandles(handle ParallelHandle, errHandle ParallelErrorHandle) int

AddHandles @handle 需要处理 cancelCtx 事件

func (*ParallelMgt) AddHttpRequest added in v0.1.3

func (r *ParallelMgt) AddHttpRequest(client *http.Client, newReqHandler ParallelHttpNewRequest, reqFormatHandler ParallelHttpResponseFormat) int

func (*ParallelMgt) Run added in v0.1.3

func (r *ParallelMgt) Run(timeout time.Duration, failType ParallelFailType) []error

type Set

type Set[T constraints.Ordered] map[T]EmptyStruct

func Slice2Set

func Slice2Set[E any, K constraints.Ordered](s []E, fn func(v *E) K) Set[K]

Slice2Set 切片结构体转换为 map[结构体Field]struct{}

func Slice2SetFilter

func Slice2SetFilter[E any, K constraints.Ordered](s []E, fn func(v *E) (K, bool)) Set[K]

Slice2SetFilter 切片结构体转换为 map[结构体Field]struct{}

func (Set[T]) Add

func (m Set[T]) Add(v T)

func (Set[T]) Has

func (m Set[T]) Has(v T) bool

func (Set[T]) ToSlice

func (m Set[T]) ToSlice() []T

type SplitSliceData

type SplitSliceData interface {
	Len() int
	Compare(i, j int) bool
}

SplitSliceData split 切割 slice 数据结构

type TimeLately added in v0.1.3

type TimeLately int
const (
	TimeLatelyBefore TimeLately = 1
	TimeLatelyAfter  TimeLately = 2
)

Jump to

Keyboard shortcuts

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