baseutils

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DurationDay      = time.Hour * 24
	DurationMonth    = DurationDay * 30
	MaxDurationMonth = DurationDay * 31
	DurationYear     = DurationDay * 365
	MaxDurationYear  = DurationDay * 366
)
View Source
const (
	SpillBufferMemoryWaterMark = 1024 * 1024 * 1 // 1MB 内存水位线
)

Variables

View Source
var ReflectTimeType = stl.ReflectType[time.Time]()
View Source
var StdBase64DecodeString = base64.StdEncoding.DecodeString
View Source
var StdBase64EncodeToString = base64.StdEncoding.EncodeToString
View Source
var UrlBase64DecodeString = base64.URLEncoding.DecodeString
View Source
var UrlBase64EncodeToString = base64.URLEncoding.EncodeToString

Functions

func AlignNextTime added in v1.0.8

func AlignNextTime(base time.Time, interval time.Duration, offset time.Duration) time.Time

func Base64Decode added in v1.0.6

func Base64Decode(enc *base64.Encoding, data []byte) ([]byte, error)

func Base64Encode added in v1.0.6

func Base64Encode(enc *base64.Encoding, data []byte) []byte

func DayOf added in v1.0.58

func DayOf(t time.Time) time.Time

获取日期

func DereferenceReflectPointer added in v1.0.35

func DereferenceReflectPointer(ptr reflect.Value) (result reflect.Value, ok bool)

func DereferenceReflectPointerWithError added in v1.0.35

func DereferenceReflectPointerWithError(ptr reflect.Value) (result reflect.Value, err error)

func Friday added in v1.0.99

func Friday(t time.Time) time.Time

func GenerateRsaKey added in v1.0.6

func GenerateRsaKey(bits int) (publicKey, privateKey []byte, err error)

func GetYear2050 added in v1.0.58

func GetYear2050() time.Time

2050年1月1日

func GetYear3000 added in v1.0.58

func GetYear3000() time.Time

3000年1月1日

func GetYear5000 added in v1.0.58

func GetYear5000() time.Time

5000年1月1日

func Gunzip added in v1.0.72

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

func Gzip added in v1.0.72

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

func HashData added in v1.0.6

func HashData(hash crypto.Hash, datas ...[]byte) ([]byte, error)

func HashDataSilently added in v1.0.6

func HashDataSilently(hash crypto.Hash, datas ...[]byte) []byte

func HashSum added in v1.0.80

func HashSum(hash hash.Hash, data []byte) []byte

func HashSumBtob added in v1.0.80

func HashSumBtob(hash hash.Hash, data []byte) []byte

func HashSumBtos added in v1.0.80

func HashSumBtos(hash hash.Hash, data []byte) string

func HashSumStob added in v1.0.80

func HashSumStob(hash hash.Hash, data string) []byte

func HashSumStos added in v1.0.80

func HashSumStos(hash hash.Hash, data string) string

func IteratorDataToTypelessSliceByReflect added in v1.0.35

func IteratorDataToTypelessSliceByReflect(data any) ([]any, error)

func IteratorDataToTypelessSliceByReflectValue added in v1.0.35

func IteratorDataToTypelessSliceByReflectValue(data reflect.Value) ([]any, error)

func MapKeyValuePairPtrsByReflect added in v1.0.35

func MapKeyValuePairPtrsByReflect(m any) (stl.KeyValuePairPtrs[any, any], error)

func MapKeyValuePairPtrsByReflectValue added in v1.0.35

func MapKeyValuePairPtrsByReflectValue(m reflect.Value) stl.KeyValuePairPtrs[any, any]

func MapKeyValuePairsByReflect added in v1.0.35

func MapKeyValuePairsByReflect(m any) (stl.KeyValuePairs[any, any], error)

func MapKeyValuePairsByReflectValue added in v1.0.35

func MapKeyValuePairsByReflectValue(m reflect.Value) stl.KeyValuePairs[any, any]

func MapListByReflect added in v1.0.35

func MapListByReflect[T any](datas any, mapper func(data any) T) ([]T, error)

func MapListByReflectValue added in v1.0.35

func MapListByReflectValue[T any](datas reflect.Value, mapper func(data any) T) []T

func MapListToAnysByReflect added in v1.0.35

func MapListToAnysByReflect(datas any) ([]any, error)

func MapListToAnysByReflectValue added in v1.0.35

func MapListToAnysByReflectValue(datas reflect.Value) []any

func MapMapWithReflect added in v1.0.35

func MapMapWithReflect[T any](m any, mapper func(stl.KeyValuePair[any, any]) T) ([]T, error)

func MapMapWithReflectValue added in v1.0.35

func MapMapWithReflectValue[T any](m reflect.Value, mapper func(stl.KeyValuePair[any, any]) T) []T

func MaxTime added in v1.0.32

func MaxTime(times ...time.Time) time.Time

func MinTime added in v1.0.32

func MinTime(times ...time.Time) time.Time

func Monday added in v1.0.99

func Monday(t time.Time) time.Time

func NewHash added in v1.0.6

func NewHash(hash crypto.Hash) (hash.Hash, error)

func NewTimes added in v1.0.33

func NewTimes(times ...time.Time) []time.Time

func NextWeekday added in v1.0.99

func NextWeekday(t time.Time, weekday time.Weekday) time.Time

func PanicRecover added in v1.0.69

func PanicRecover(panicError *error, onPanicErrors ...func(*PanicError)) error

func ParseJsonRawMessage added in v1.0.24

func ParseJsonRawMessage[Data any](message JsonRawMessage) (data Data, err error)

func ParseJsonRawMessageAsPointer added in v1.0.24

func ParseJsonRawMessageAsPointer[Ptr *Data, Data any](message JsonRawMessage) (Ptr, error)

func ParseNetloc added in v1.0.11

func ParseNetloc(loc string, defaultAddr string, defaultPort int) (addr string, port int, err error)

func Pkcs5Padding added in v1.0.6

func Pkcs5Padding(data []byte, blockSize int) []byte

func Pkcs5Unpadding added in v1.0.6

func Pkcs5Unpadding(data []byte) []byte

func Saturday added in v1.0.99

func Saturday(t time.Time) time.Time

func SortTimes added in v1.0.33

func SortTimes(times ...time.Time) []time.Time

func StdBase64Decode added in v1.0.72

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

func StdBase64Encode added in v1.0.72

func StdBase64Encode(data []byte) []byte

func StringToBytes added in v1.0.80

func StringToBytes(s string) []byte

todo: where to move?

func Sunday added in v1.0.99

func Sunday(t time.Time) time.Time

func Thursday added in v1.0.99

func Thursday(t time.Time) time.Time

func Today added in v1.0.58

func Today() time.Time

今天

func Tomorrow added in v1.0.58

func Tomorrow() time.Time

明天

func Tuesday added in v1.0.99

func Tuesday(t time.Time) time.Time

func UrlBase64Decode added in v1.0.72

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

func UrlBase64Encode added in v1.0.72

func UrlBase64Encode(data []byte) []byte

func Wednesday added in v1.0.99

func Wednesday(t time.Time) time.Time

func WeekdayOf added in v1.0.99

func WeekdayOf(t time.Time, weekday time.Weekday) time.Time

func WrapTimeFields added in v1.0.48

func WrapTimeFields(data any, wrapper func(time.Time) time.Time) error

func WrapTimeFieldsByReflectValue added in v1.0.48

func WrapTimeFieldsByReflectValue(value reflect.Value, wrapper func(time.Time) time.Time) error

func Yesterday added in v1.0.58

func Yesterday() time.Time

昨天

Types

type AesCipher added in v1.0.6

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

func NewAesCipher added in v1.0.6

func NewAesCipher(key []byte, bits int) (*AesCipher, error)

func (*AesCipher) Decrypt added in v1.0.6

func (a *AesCipher) Decrypt(cipherdata []byte, b64 bool) ([]byte, error)

func (*AesCipher) Encrypt added in v1.0.6

func (a *AesCipher) Encrypt(plaintext []byte, b64 bool) ([]byte, error)

type BadTypeError added in v1.0.35

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

func NewBadTypeError added in v1.0.35

func NewBadTypeError(expected, given string) BadTypeError

func NewBadTypeErrorWithGivenReflectType added in v1.0.35

func NewBadTypeErrorWithGivenReflectType(expected, given reflect.Type) BadTypeError

func NewBlankBadTypeError added in v1.0.35

func NewBlankBadTypeError() BadTypeError

func (BadTypeError) Error added in v1.0.35

func (e BadTypeError) Error() string

func (BadTypeError) WithExpected added in v1.0.35

func (err BadTypeError) WithExpected(expected string) BadTypeError

func (BadTypeError) WithExpectedReflectType added in v1.0.35

func (err BadTypeError) WithExpectedReflectType(expected reflect.Type) BadTypeError

func (BadTypeError) WithGiven added in v1.0.35

func (err BadTypeError) WithGiven(given string) BadTypeError

func (BadTypeError) WithGivenReflectType added in v1.0.35

func (err BadTypeError) WithGivenReflectType(given reflect.Type) BadTypeError

type Closers added in v1.0.88

type Closers []io.Closer

func NewClosers added in v1.0.88

func NewClosers(closers ...io.Closer) Closers

func (Closers) Append added in v1.0.88

func (closers Closers) Append(others ...io.Closer) Closers

func (Closers) Close added in v1.0.88

func (closers Closers) Close() error

func (Closers) Concat added in v1.0.88

func (closers Closers) Concat(others ...Closers) Closers

func (Closers) PurgeNil added in v1.0.88

func (closers Closers) PurgeNil() Closers

func (Closers) Simplify added in v1.0.88

func (closers Closers) Simplify() io.Closer

type CookieNotFoundError

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

func NewCookieNotFoundError

func NewCookieNotFoundError(name string) CookieNotFoundError

func (CookieNotFoundError) Error

func (e CookieNotFoundError) Error() string

func (CookieNotFoundError) Name

func (e CookieNotFoundError) Name() string

type DateTime added in v1.0.77

type DateTime time.Time

func (DateTime) MarshalJSON added in v1.0.77

func (t DateTime) MarshalJSON() ([]byte, error)

func (DateTime) Native added in v1.0.77

func (t DateTime) Native() time.Time

func (*DateTime) UnmarshalJSON added in v1.0.77

func (t *DateTime) UnmarshalJSON(data []byte) error

type EnvironmentVariableNotFoundError

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

func NewEnvironmentVariableNotFoundError

func NewEnvironmentVariableNotFoundError(name string) EnvironmentVariableNotFoundError

func (EnvironmentVariableNotFoundError) Error

func (EnvironmentVariableNotFoundError) Name

type Errors added in v1.0.8

type Errors = stl.Errors

func ReflectMap added in v1.0.71

func ReflectMap(datas any, methodName string, methodOutValueIndex, methodOutErrorIndex int, args []reflect.Value, stopWhenError bool) (values any, errs Errors, err error)

ReflectMap traverses elements in datas, calls the specified method on each element, and returns the results as a slice.

Parameters: - datas: a slice or array of data to process - methodName: the name of the method to call on each element - methodOutValueIndex: the index of the value returned by the method - methodOutErrorIndex: the index of the error returned by the method - args: additional arguments to pass to the method (can be empty) - stopWhenError: whether to stop processing when an error occurs

Returns: - values: a slice containing the values returned by the method calls - error: the first error encountered, or nil if no errors occurred

type GenericNotFoundError added in v1.0.25

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

func NewGenericNotFoundError added in v1.0.25

func NewGenericNotFoundError(t, name string) GenericNotFoundError

func (GenericNotFoundError) Error added in v1.0.25

func (e GenericNotFoundError) Error() string

func (GenericNotFoundError) Name added in v1.0.25

func (e GenericNotFoundError) Name() string

func (GenericNotFoundError) Type added in v1.0.25

func (e GenericNotFoundError) Type() string

type HashPro added in v1.0.80

type HashPro struct {
	hash.Hash
}

func NewHashPro added in v1.0.80

func NewHashPro(hash hash.Hash) *HashPro

func (*HashPro) Native added in v1.0.80

func (hash *HashPro) Native() hash.Hash

func (*HashPro) SumBtob added in v1.0.80

func (hash *HashPro) SumBtob(data []byte) []byte

func (*HashPro) SumBtos added in v1.0.80

func (hash *HashPro) SumBtos(data []byte) string

func (*HashPro) SumStob added in v1.0.80

func (hash *HashPro) SumStob(data string) []byte

func (*HashPro) SumStos added in v1.0.80

func (hash *HashPro) SumStos(data string) string

type Hasher added in v1.0.80

type Hasher func() hash.Hash

func GetMd5Hasher added in v1.0.80

func GetMd5Hasher() Hasher

func GetSha1Hasher added in v1.0.80

func GetSha1Hasher() Hasher

func GetSha224Hasher added in v1.0.80

func GetSha224Hasher() Hasher

func GetSha256Hasher added in v1.0.80

func GetSha256Hasher() Hasher

func GetSha512Hasher added in v1.0.80

func GetSha512Hasher() Hasher

func (Hasher) New added in v1.0.80

func (hasher Hasher) New() hash.Hash

func (Hasher) NewHashPro added in v1.0.80

func (hasher Hasher) NewHashPro() *HashPro

func (Hasher) Sum added in v1.0.80

func (hasher Hasher) Sum(data []byte) []byte

func (Hasher) SumBstob added in v1.0.80

func (hasher Hasher) SumBstob(datas [][]byte) []byte

func (Hasher) SumBstobX added in v1.0.80

func (hasher Hasher) SumBstobX(datas ...[]byte) []byte

func (Hasher) SumBstos added in v1.0.80

func (hasher Hasher) SumBstos(datas [][]byte) string

func (Hasher) SumBstosX added in v1.0.80

func (hasher Hasher) SumBstosX(datas ...[]byte) string

func (Hasher) SumBtob added in v1.0.80

func (hasher Hasher) SumBtob(data []byte) []byte

func (Hasher) SumBtos added in v1.0.80

func (hasher Hasher) SumBtos(data []byte) string

func (Hasher) SumReader added in v1.0.90

func (hasher Hasher) SumReader(reader io.Reader) []byte

func (Hasher) SumRtob added in v1.0.90

func (hasher Hasher) SumRtob(reader io.Reader) []byte

func (Hasher) SumRtos added in v1.0.90

func (hasher Hasher) SumRtos(reader io.Reader) string

func (Hasher) SumSstob added in v1.0.80

func (hasher Hasher) SumSstob(datas []string) []byte

func (Hasher) SumSstobX added in v1.0.80

func (hasher Hasher) SumSstobX(datas ...string) []byte

func (Hasher) SumSstos added in v1.0.80

func (hasher Hasher) SumSstos(datas []string) string

func (Hasher) SumSstosX added in v1.0.80

func (hasher Hasher) SumSstosX(datas ...string) string

func (Hasher) SumStob added in v1.0.80

func (hasher Hasher) SumStob(data string) []byte

func (Hasher) SumStos added in v1.0.80

func (hasher Hasher) SumStos(data string) string

type IntraDayTime added in v1.0.58

type IntraDayTime time.Duration

func MustParseFormattedIntraDayTime added in v1.0.58

func MustParseFormattedIntraDayTime(layout, value string) IntraDayTime

func MustParseIntraDayTime added in v1.0.58

func MustParseIntraDayTime(s string) IntraDayTime

func ParseFormattedIntraDayTime added in v1.0.58

func ParseFormattedIntraDayTime(layout, value string) (IntraDayTime, error)

func ParseIntraDayTime added in v1.0.58

func ParseIntraDayTime(s string) (IntraDayTime, error)

func (IntraDayTime) Duration added in v1.0.58

func (t IntraDayTime) Duration() time.Duration

func (IntraDayTime) Format added in v1.0.58

func (t IntraDayTime) Format(layout string) string

func (IntraDayTime) MarshalJSON added in v1.0.58

func (t IntraDayTime) MarshalJSON() ([]byte, error)

func (IntraDayTime) Parts added in v1.0.58

func (t IntraDayTime) Parts() (int, int, int, int)

func (IntraDayTime) String added in v1.0.58

func (t IntraDayTime) String() string

func (*IntraDayTime) UnmarshalJSON added in v1.0.58

func (t *IntraDayTime) UnmarshalJSON(data []byte) error

type IntraDayTimes added in v1.1.4

type IntraDayTimes []IntraDayTime

func (IntraDayTimes) Empty added in v1.1.4

func (ts IntraDayTimes) Empty() bool

func (IntraDayTimes) Len added in v1.1.4

func (ts IntraDayTimes) Len() int

func (IntraDayTimes) Sort added in v1.1.4

func (ts IntraDayTimes) Sort(less func(a, b IntraDayTime) bool) IntraDayTimes

func (IntraDayTimes) SortAsc added in v1.1.4

func (ts IntraDayTimes) SortAsc() IntraDayTimes

type JsonAny added in v1.0.24

type JsonAny = any

type JsonArray added in v1.0.24

type JsonArray = []JsonAny

type JsonMap added in v1.0.24

type JsonMap = JsonObject

type JsonObject added in v1.0.24

type JsonObject = map[string]JsonAny

type JsonRawMessage added in v1.0.24

type JsonRawMessage struct {
	json.RawMessage
}

func (JsonRawMessage) UnmarshalAsInt added in v1.0.24

func (message JsonRawMessage) UnmarshalAsInt() (int, error)

func (JsonRawMessage) UnmarshalAsString added in v1.0.24

func (message JsonRawMessage) UnmarshalAsString() (string, error)

func (JsonRawMessage) UnmarshalTo added in v1.0.24

func (message JsonRawMessage) UnmarshalTo(dst interface{}) error

type JsonRawMessageMap added in v1.0.24

type JsonRawMessageMap map[string]JsonRawMessage

func (JsonRawMessageMap) Lookup added in v1.0.24

func (m JsonRawMessageMap) Lookup(key string) (JsonRawMessage, bool)

type JsonRawStrMessage added in v1.0.94

type JsonRawStrMessage string

func (JsonRawStrMessage) MarshalJSON added in v1.0.94

func (msg JsonRawStrMessage) MarshalJSON() ([]byte, error)

func (*JsonRawStrMessage) UnmarshalJSON added in v1.0.94

func (msg *JsonRawStrMessage) UnmarshalJSON(data []byte) error

type ListIteratorByReflect added in v1.0.35

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

func NewSliceIteratorByReflectValue added in v1.0.35

func NewSliceIteratorByReflectValue(slice reflect.Value) *ListIteratorByReflect

func (*ListIteratorByReflect) Data added in v1.0.35

func (it *ListIteratorByReflect) Data() any

func (*ListIteratorByReflect) Len added in v1.0.35

func (it *ListIteratorByReflect) Len() int

func (*ListIteratorByReflect) Next added in v1.0.35

func (it *ListIteratorByReflect) Next() bool

type MapIteratorByReflect added in v1.0.35

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

func NewMapIteratorByReflect added in v1.0.35

func NewMapIteratorByReflect(m reflect.Value) *MapIteratorByReflect

func (*MapIteratorByReflect) Data added in v1.0.35

func (*MapIteratorByReflect) Len added in v1.0.35

func (it *MapIteratorByReflect) Len() int

func (*MapIteratorByReflect) Next added in v1.0.35

func (it *MapIteratorByReflect) Next() bool

type NilError added in v1.0.57

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

func NewNilError added in v1.0.57

func NewNilError(name string) NilError

func NewNilErrorFromNames added in v1.0.57

func NewNilErrorFromNames(names ...string) NilError

func (NilError) Error added in v1.0.57

func (err NilError) Error() string

type NotImplementedError

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

func NewNotImplementedError

func NewNotImplementedError(hint string) NotImplementedError

func (NotImplementedError) Error

func (e NotImplementedError) Error() string

type PanicError added in v1.0.69

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

func NewPanicError added in v1.0.69

func NewPanicError(exception any, stack string) *PanicError

func (*PanicError) Error added in v1.0.69

func (err *PanicError) Error() string

type PrivateKeyCipher added in v1.0.6

type PrivateKeyCipher struct {
	PublicKeyCipher
	// contains filtered or unexported fields
}

func NewPrivateKeyCipher added in v1.0.6

func NewPrivateKeyCipher(key *rsa.PrivateKey) *PrivateKeyCipher

func (*PrivateKeyCipher) Decrypt added in v1.0.6

func (c *PrivateKeyCipher) Decrypt(ciphertext []byte) ([]byte, error)

func (*PrivateKeyCipher) DecryptPro added in v1.0.6

func (c *PrivateKeyCipher) DecryptPro(ciphertext []byte, decrypter RsaDecrypter, random io.Reader) ([]byte, error)

func (*PrivateKeyCipher) Sign added in v1.0.6

func (c *PrivateKeyCipher) Sign(data []byte) ([]byte, error)

func (*PrivateKeyCipher) SignPro added in v1.0.6

func (c *PrivateKeyCipher) SignPro(data []byte, signer RsaSigner, random io.Reader, hash crypto.Hash) ([]byte, error)

type PublicKeyCipher added in v1.0.6

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

func NewPublicKeyCipher added in v1.0.6

func NewPublicKeyCipher(key *rsa.PublicKey) *PublicKeyCipher

func (*PublicKeyCipher) Encrypt added in v1.0.6

func (c *PublicKeyCipher) Encrypt(plaintext []byte) ([]byte, error)

func (*PublicKeyCipher) EncryptPro added in v1.0.6

func (c *PublicKeyCipher) EncryptPro(plaintext []byte, encrypter RsaEncrypter, random io.Reader) ([]byte, error)

func (*PublicKeyCipher) Verify added in v1.0.6

func (c *PublicKeyCipher) Verify(data, sign []byte) error

func (*PublicKeyCipher) VerifyPro added in v1.0.6

func (c *PublicKeyCipher) VerifyPro(data, sign []byte, verifier RsaVerifier, hash crypto.Hash) error

type RsaDecrypter added in v1.0.6

type RsaDecrypter = func(io.Reader, *rsa.PrivateKey, []byte) ([]byte, error)

type RsaEncrypter added in v1.0.6

type RsaEncrypter = func(io.Reader, *rsa.PublicKey, []byte) ([]byte, error)

type RsaSigner added in v1.0.6

type RsaSigner = func(io.Reader, *rsa.PrivateKey, crypto.Hash, []byte) ([]byte, error)

type RsaVerifier added in v1.0.6

type RsaVerifier = func(*rsa.PublicKey, crypto.Hash, []byte, []byte) error

type SpillBuffer added in v1.1.0

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

func NewSpillBuffer added in v1.1.0

func NewSpillBuffer(memoryWaterMark int, withMutex bool) *SpillBuffer

func (*SpillBuffer) Close added in v1.1.0

func (sb *SpillBuffer) Close() error

func (*SpillBuffer) Read added in v1.1.0

func (sb *SpillBuffer) Read(p []byte) (n int, err error)

func (*SpillBuffer) WithMemoryWaterMark added in v1.1.0

func (sb *SpillBuffer) WithMemoryWaterMark(waterMark int) *SpillBuffer

func (*SpillBuffer) WithMutex added in v1.1.0

func (sb *SpillBuffer) WithMutex() *SpillBuffer

func (*SpillBuffer) Write added in v1.1.0

func (sb *SpillBuffer) Write(p []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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