tools

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 33 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	TimeTruncater      = time.Millisecond
	DefaultTimeFormat  = "2006-01-02 15:04:05 MST"
	TimeFormatWithMS   = "2006-01-02 15:04:05.000 MST"
	DefaultParseLayout = time.DateTime

	DateTruncater     = 24 * time.Hour
	DefaultDateFormat = time.DateOnly
)
View Source
const (
	// QRCodeDefaultLogoCover is the default logo cover ratio when logo is enabled.
	QRCodeDefaultLogoCover = 0.20
)

Variables

View Source
var (
	ErrNilSource = errors.New("tools: nil source value")
	ErrNilValue  = errors.New("tools: nil value")
)
View Source
var (
	ErrMissingText        = errors.New("tools/qr: text is missing")
	ErrOutputPathEmpty    = errors.New("tools/qr: output path cannot be empty")
	ErrOutputWriterNil    = errors.New("tools/qr: output writer cannot be nil")
	ErrLogoSourceConflict = errors.New("tools/qr: logo source conflict")
)
View Source
var (
	// ByteSliceType is the reflect.Type for []byte.
	ByteSliceType = reflect.TypeOf([]byte{})
	// StringType is the reflect.Type for string.
	StringType = reflect.TypeOf("")
	// StringSliceType is the reflect.Type for []string.
	StringSliceType = reflect.TypeOf([]string{})
	// Int64Type is the reflect.Type for int64.
	Int64Type = reflect.TypeOf(int64(0))
	// Int64SliceType is the reflect.Type for []int64.
	Int64SliceType = reflect.TypeOf([]int64{})
)

Functions

func Abs added in v0.1.1

func Abs[I ~int | ~int8 | ~int16 | ~int32 | ~int64](i I) I

func AllMapValueSlices added in v0.1.3

func AllMapValueSlices[K comparable, T comparable](m map[K][]T, needDedup ...bool) []T

func BatchCall added in v0.1.2

func BatchCall[T any](op func([]T) bool, batchSize int, ts ...T)

func CopySlice

func CopySlice[T any](src []T) []T

func GenerateQRCode added in v0.2.0

func GenerateQRCode(text, output string, options QRCodeOptions) error

GenerateQRCode generates a QR image file with explicit text and options.

func GenerateQRCodeToWriter added in v0.2.0

func GenerateQRCodeToWriter(text string, output io.Writer, options QRCodeOptions) error

GenerateQRCodeToWriter generates a QR code PNG to writer with explicit text and options.

func Hash256 added in v0.2.2

func Hash256(hasher hash.Hash, in ...[]byte) []byte

func HostIP added in v0.3.0

func HostIP(hostOrIp string) (net.IP, error)

HostIP parses an input string (Host/IP/CIDR/Host:Port) into a valid net.IP object.

Supported Formats:

  • Plain IP: "192.168.1.1", "fe80::1"
  • Address with Port: "192.168.1.1:8080", "example.com:443"
  • CIDR Notation: "192.168.1.100/24" (Extracts host IP "192.168.1.100", not network address ".0")
  • Domain Names: "localhost", "example.com" (Triggers DNS lookup, prioritizes IPv4)

Parameters:

  • hostOrIp: The string to be parsed.

Returns:

  • net.IP: Resolved standard IP object.
  • error: Returned if format parsing or DNS lookup fails.

func IF added in v0.0.2

func IF[T any](condition bool, trueValue T, falseValue T) T

func IndirectType added in v0.1.1

func IndirectType(typ reflect.Type) reflect.Type

IndirectType dereferences typ until it reaches a non-pointer type. If typ is not a pointer, it is returned unchanged.

func IndirectValue added in v0.1.1

func IndirectValue(val reflect.Value) reflect.Value

IndirectValue dereferences val until it reaches a non-pointer value. If val is not a pointer, it is returned unchanged.

func IsByteSlice added in v0.1.0

func IsByteSlice(typ reflect.Type) bool

IsByteSlice reports whether the given reflect.Type represents a byte slice ([]byte).

func IsDefaultZero added in v0.1.0

func IsDefaultZero[T any](t T) bool

IsDefaultZero reports whether t is the zero value of its type. An invalid reflect.Value is also considered zero.

func IsNil added in v0.2.2

func IsNil(v any) bool

IsNil reports whether v is nil. It handles both untyped nil and typed nil values of kinds Chan, Func, Interface, Map, Ptr, and Slice. An invalid reflect.Value is also considered nil.

func JsonPrettyString added in v0.0.5

func JsonPrettyString(m any) (string, error)

func JsonString

func JsonString(m any) (string, error)

func LocalFirstIP added in v0.3.0

func LocalFirstIP(fn strategy.Func) (net.IP, error)

LocalFirstIP scans local network interfaces sequentially and returns the first IP matching the strategy.

Parameters:

  • fn: Filter strategy callback. Accepts Interface and IP, returns bool. If fn is nil, no filtering is applied.

Returns:

  • net.IP: The first matching IP address.
  • error: Returned when reading interfaces fails or no matching IP is found.

func LocalMachineIfsIP2MAC added in v0.3.0

func LocalMachineIfsIP2MAC(fn strategy.Func) (map[IPString]net.HardwareAddr, error)

LocalMachineIfsIP2MAC scans all local network interfaces and extracts a map of IP addresses to MAC addresses matching the given strategy function.

Parameters:

  • fn: Filter strategy callback. Accepts Interface and IP, returns bool. If fn is nil, no filtering is applied.

Returns:

  • map[IPString]net.HardwareAddr: Map where key is normalized IP string and value is deep-copied HardwareAddr.
  • error: Returned when reading system network interfaces fails.

func MustJsonPrettyString added in v0.0.5

func MustJsonPrettyString(m any) string

func MustJsonString added in v0.0.5

func MustJsonString(m any) string

func NewIDValuer added in v0.1.1

func NewIDValuer(ids ...int64) []driver.Valuer

func OpenWriteFile added in v0.1.2

func OpenWriteFile(fullFilePathName string) (*os.File, error)

func RandomBytes added in v0.1.2

func RandomBytes(length int) []byte

func RemoveFile added in v0.1.2

func RemoveFile(fullFilePathName string) error

func SetByteSliceValue added in v0.1.0

func SetByteSliceValue(val reflect.Value, bs []byte) error

SetByteSliceValue sets the reflect.Value val (which must represent a []byte) to the contents of bs. If val's capacity is insufficient, it allocates a new slice (val must be settable in that case). Returns an error if val cannot be set.

func SplitNetAddr added in v0.1.1

func SplitNetAddr(addr string) (host string, port int)

SplitNetAddr like host:port to host and port if there's no valid host exists, return "" if there's no valid port exists, return -1

func SsToTs

func SsToTs[S, T any](transmitter func(S) T, ss ...S) []T

func TsToSs

func TsToSs[T, S any](transmitter func(T) (S, bool), ts ...T) []S

func ValidAndCreateDir added in v0.1.1

func ValidAndCreateDir(pstr string, checkAndCreateIfAbsent bool) (string, error)

ValidAndCreateDir 将传入的绝对路径pstr当作文件目录,确认其存在,如果不存在则创建。并返回包含最后的路径分隔符的绝对路径字符串

func VariadicParam added in v0.1.1

func VariadicParam[T any](params []T, defaultValue ...T) T

Types

type B added in v0.0.7

type B byte

B for byte

func (B) PopCount added in v0.0.7

func (b B) PopCount() int

type Bs added in v0.0.7

type Bs []byte

func (Bs) PopCount added in v0.0.7

func (bs Bs) PopCount() int

type Date added in v0.1.2

type Date time.Time

func NewADate added in v0.1.2

func NewADate(year int, month time.Month, day int, loc ...*time.Location) Date

func (Date) Formalize added in v0.1.2

func (d Date) Formalize() Date

func (Date) MarshalJSON added in v0.1.2

func (d Date) MarshalJSON() ([]byte, error)

func (*Date) Scan added in v0.1.2

func (d *Date) Scan(value any) error

func (Date) String added in v0.1.2

func (d Date) String() string

func (Date) ToTime added in v0.1.2

func (d Date) ToTime() Time

func (*Date) UnmarshalJSON added in v0.1.2

func (d *Date) UnmarshalJSON(data []byte) error

func (Date) Value added in v0.1.2

func (d Date) Value() (driver.Value, error)

type Exister added in v0.1.2

type Exister[K comparable] interface {
	IsExist(k K) bool
}

type F added in v0.0.7

type F float64

F for float64

func (F) ID added in v0.0.7

func (f F) ID() (i ID, overflow bool)

func (F) Int added in v0.0.7

func (f F) Int() (i int64, flowed bool)

func (F) MustID added in v0.0.7

func (f F) MustID() ID

func (F) MustInt added in v0.0.7

func (f F) MustInt() int64

type ID added in v0.0.7

type ID int64

func (ID) Decr added in v0.0.7

func (id ID) Decr() int64

func (ID) FullBytes added in v0.0.7

func (id ID) FullBytes() []byte

func (ID) Incr added in v0.0.7

func (id ID) Incr() int64

func (ID) Int added in v0.0.7

func (id ID) Int() int64

func (ID) IsValid added in v0.0.7

func (id ID) IsValid() bool

func (ID) PadZeros added in v0.0.7

func (id ID) PadZeros() string

func (ID) String added in v0.0.7

func (id ID) String() string

type IPString added in v0.3.0

type IPString string

IPString is a custom type for using IP addresses as map keys reliably.

type JSON

type JSON json.RawMessage

func (*JSON) Bytes

func (j *JSON) Bytes() []byte

func (*JSON) Clone

func (j *JSON) Clone() JSON

func (*JSON) Equal

func (j *JSON) Equal(o *JSON) bool

func (JSON) Format

func (j JSON) Format(f fmt.State, c rune)

func (JSON) IsNull

func (j JSON) IsNull() bool

func (JSON) MarshalJSON

func (j JSON) MarshalJSON() ([]byte, error)

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

func (*JSON) String

func (j *JSON) String() string

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(data []byte) error

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

type JSONArray added in v0.0.6

type JSONArray[T comparable] []T

func NewJSONArray added in v0.0.6

func NewJSONArray[T comparable](data JSON) (ja JSONArray[T], err error)

func (JSONArray[T]) Equal added in v0.0.6

func (ja JSONArray[T]) Equal(jt JSONArray[T]) bool

func (JSONArray[T]) Index added in v0.0.6

func (ja JSONArray[T]) Index(v T) int

func (JSONArray[T]) MarshalJSON added in v0.0.6

func (ja JSONArray[T]) MarshalJSON() ([]byte, error)

func (JSONArray[T]) ToArray added in v0.0.6

func (ja JSONArray[T]) ToArray() []T

func (JSONArray[T]) ToJSON added in v0.0.6

func (ja JSONArray[T]) ToJSON() (JSON, error)

func (JSONArray[T]) ToNotNullJSON added in v0.0.6

func (ja JSONArray[T]) ToNotNullJSON() (NotNullJSON, error)

type JSONBuilder

type JSONBuilder struct{}

func (JSONBuilder) FromObj

func (b JSONBuilder) FromObj(obj any) (JSON, error)

func (JSONBuilder) FromString

func (b JSONBuilder) FromString(jsonStr string) (JSON, error)

func (JSONBuilder) NoErrObj

func (b JSONBuilder) NoErrObj(obj any) JSON

func (JSONBuilder) NoErrString

func (b JSONBuilder) NoErrString(jsonStr string) JSON

type KKMap

type KKMap[K1 comparable, K2 comparable, V any] map[K1]map[K2]V

func (KKMap[K1, K2, V]) Delete

func (kkm KKMap[K1, K2, V]) Delete(k1 K1, k2 K2)

func (KKMap[K1, K2, V]) DeleteKey

func (kkm KKMap[K1, K2, V]) DeleteKey(k1 K1)

func (KKMap[K1, K2, V]) Get

func (kkm KKMap[K1, K2, V]) Get(k1 K1, k2 K2) (v V, exist bool)

func (KKMap[K1, K2, V]) IsExist added in v0.0.4

func (kkm KKMap[K1, K2, V]) IsExist(k1 K1, k2 K2) (exist bool)

func (KKMap[K1, K2, V]) IsExistKey added in v0.0.5

func (kkm KKMap[K1, K2, V]) IsExistKey(k1 K1) (exist bool)

func (KKMap[K1, K2, V]) Put

func (kkm KKMap[K1, K2, V]) Put(k1 K1, k2 K2, v V) KKMap[K1, K2, V]

func (KKMap[K1, K2, V]) PutKey added in v0.0.4

func (kkm KKMap[K1, K2, V]) PutKey(k1 K1, km2 map[K2]V) KKMap[K1, K2, V]

func (KKMap[K1, K2, V]) Range added in v0.0.3

func (kkm KKMap[K1, K2, V]) Range(handler func(k1 K1, k2 K2, v V) (goon bool))

type KMap

type KMap[K comparable, V any] map[K]V

func (KMap[K, V]) Delete

func (km KMap[K, V]) Delete(ks ...K)

func (KMap[K, V]) ExistingList added in v0.0.5

func (km KMap[K, V]) ExistingList(keys ...K) []V

func (KMap[K, V]) Get

func (km KMap[K, V]) Get(k K) (v V, exist bool)

func (KMap[K, V]) IsExist

func (km KMap[K, V]) IsExist(key K) bool

func (KMap[K, V]) KeySeq added in v0.1.2

func (km KMap[K, V]) KeySeq(filters ...func(k K, v V) bool) iter.Seq[K]

func (KMap[K, V]) Keys

func (km KMap[K, V]) Keys(filters ...func(k K, v V) bool) []K

func (KMap[K, V]) List

func (km KMap[K, V]) List(keys ...K) []V

func (KMap[K, V]) Map

func (km KMap[K, V]) Map() map[K]V

func (KMap[K, V]) Merge

func (km KMap[K, V]) Merge(kmo KMap[K, V]) KMap[K, V]

func (KMap[K, V]) Put

func (km KMap[K, V]) Put(key K, value V) KMap[K, V]

func (KMap[K, V]) Puts added in v0.1.1

func (km KMap[K, V]) Puts(it iter.Seq2[K, V]) KMap[K, V]

func (KMap[K, V]) RangeSubMap added in v0.1.2

func (km KMap[K, V]) RangeSubMap(batchSize int, ranger func(m KMap[K, V]) bool)

func (KMap[K, V]) SubMap added in v0.0.4

func (km KMap[K, V]) SubMap(ks ...K) KMap[K, V]

SubMap generate a new map with all keys from ks, even if there's no corresponding value in km.

func (KMap[K, V]) Values

func (km KMap[K, V]) Values(filters ...func(k K, v V) bool) []V

func (KMap[K, V]) ValuesSeq added in v0.1.1

func (km KMap[K, V]) ValuesSeq(filters ...func(k K, v V) bool) iter.Seq[V]

type KS

type KS[K comparable] []K

func (KS[K]) All added in v0.1.1

func (ks KS[K]) All() iter.Seq[K]

func (KS[K]) Append added in v0.0.5

func (ks KS[K]) Append(k K) KS[K]

func (KS[K]) Clone

func (ks KS[K]) Clone() KS[K]

func (KS[K]) Contains

func (ks KS[K]) Contains(tgt K) bool

func (KS[K]) Dedup

func (ks KS[K]) Dedup(validators ...func(k K) bool) KS[K]

func (KS[K]) DedupRange

func (ks KS[K]) DedupRange(one func(k K) error) error

func (KS[K]) Equal added in v0.0.5

func (ks KS[K]) Equal(os KS[K]) bool

func (KS[K]) In added in v0.1.2

func (ks KS[K]) In(e Exister[K]) KS[K]

func (KS[K]) IterateRemove

func (ks KS[K]) IterateRemove(tgt K) KS[K]

func (KS[K]) Map

func (ks KS[K]) Map(validators ...func(k K) bool) KSet[K]

func (KS[K]) NotIn added in v0.1.2

func (ks KS[K]) NotIn(e Exister[K]) KS[K]

func (KS[K]) Remove

func (ks KS[K]) Remove(tgts ...K) KS[K]

func (KS[K]) Slice

func (ks KS[K]) Slice() []K

func (KS[K]) Sub added in v0.0.5

func (ks KS[K]) Sub(offset, limit int) KS[K]

type KSet

type KSet[K comparable] map[K]struct{}

func NewKSet added in v0.1.2

func NewKSet[K comparable](ks ...K) KSet[K]

func (KSet[K]) Add

func (km KSet[K]) Add(ks ...K) KSet[K]

func (KSet[K]) Adds added in v0.1.2

func (km KSet[K]) Adds(it iter.Seq[K]) KSet[K]

func (KSet[K]) Append

func (km KSet[K]) Append(ks ...K) KSet[K]

func (KSet[K]) AppendSet

func (km KSet[K]) AppendSet(s KSet[K]) KSet[K]

func (KSet[K]) Appends added in v0.1.1

func (km KSet[K]) Appends(it iter.Seq[K]) KSet[K]

func (KSet[K]) CAS

func (km KSet[K]) CAS(k K) (set KSet[K], changed bool)

func (KSet[K]) Clone

func (km KSet[K]) Clone() KSet[K]

func (KSet[K]) Delete

func (km KSet[K]) Delete(ks ...K) KSet[K]

func (KSet[K]) Equal

func (km KSet[K]) Equal(o KSet[K]) bool

func (KSet[K]) ExsitingList added in v0.0.5

func (km KSet[K]) ExsitingList(ks ...K) []K

func (KSet[K]) In added in v0.1.2

func (km KSet[K]) In(input iter.Seq[K]) iter.Seq[K]

In return a sequence that in both input and current set

func (KSet[K]) IsExist

func (km KSet[K]) IsExist(k K) bool

func (KSet[K]) Keys added in v0.1.2

func (km KSet[K]) Keys() iter.Seq[K]

func (KSet[K]) RangeSubSet added in v0.1.2

func (km KSet[K]) RangeSubSet(batchSize int, ranger func(s KSet[K]) bool)

func (KSet[K]) Slice

func (km KSet[K]) Slice(emptyNil ...bool) []K

type KV

type KV[K comparable, V any] struct{}

func (KV[K, V]) KeyNotInMap

func (KV[K, V]) KeyNotInMap(m map[K]V, ks ...K) []K

func (KV[K, V]) List

func (KV[K, V]) List(keys []K, valuesMap map[K]V) []V

func (KV[K, V]) MapKeys

func (KV[K, V]) MapKeys(m map[K]V) []K

func (KV[K, V]) MapValues

func (KV[K, V]) MapValues(m map[K]V) []V

func (KV[K, V]) OneOfMap

func (KV[K, V]) OneOfMap(k K, mapper func([]K) (map[K]V, error)) (v V, err error)

func (KV[K, V]) PutToMap

func (KV[K, V]) PutToMap(m map[K]V, k K, v V) map[K]V

func (KV[K, V]) RangeByK

func (KV[K, V]) RangeByK(ks []K, m map[K]V, dowork func(k K, v V) error) error

type List added in v0.1.2

type List[T any] struct {
	// contains filtered or unexported fields
}

List represents a doubly linked list. The zero value for List is an empty list ready to use.

func NewList added in v0.1.2

func NewList[T any]() *List[T]

NewList returns an initialized list.

func (*List[T]) All added in v0.1.2

func (l *List[T]) All() iter.Seq[T]

func (*List[T]) Back added in v0.1.2

func (l *List[T]) Back() *ListElement[T]

Back returns the last element of list l or nil if the list is empty.

func (*List[T]) Front added in v0.1.2

func (l *List[T]) Front() *ListElement[T]

Front returns the first element of list l or nil if the list is empty.

func (*List[T]) Init added in v0.1.2

func (l *List[T]) Init() *List[T]

Init initializes or clears list l.

func (*List[T]) InsertAfter added in v0.1.2

func (l *List[T]) InsertAfter(v T, mark *ListElement[T]) *ListElement[T]

InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*List[T]) InsertBefore added in v0.1.2

func (l *List[T]) InsertBefore(v T, mark *ListElement[T]) *ListElement[T]

InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*List[T]) Len added in v0.1.2

func (l *List[T]) Len() int

Len returns the number of elements of list l. The complexity is O(1).

func (*List[T]) MoveAfter added in v0.1.2

func (l *List[T]) MoveAfter(e, mark *ListElement[T])

MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*List[T]) MoveBefore added in v0.1.2

func (l *List[T]) MoveBefore(e, mark *ListElement[T])

MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*List[T]) MoveToBack added in v0.1.2

func (l *List[T]) MoveToBack(e *ListElement[T])

MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List[T]) MoveToFront added in v0.1.2

func (l *List[T]) MoveToFront(e *ListElement[T])

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List[T]) PushBack added in v0.1.2

func (l *List[T]) PushBack(v T) *ListElement[T]

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*List[T]) PushBackList added in v0.1.2

func (l *List[T]) PushBackList(other *List[T])

PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.

func (*List[T]) PushFront added in v0.1.2

func (l *List[T]) PushFront(v T) *ListElement[T]

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*List[T]) PushFrontList added in v0.1.2

func (l *List[T]) PushFrontList(other *List[T])

PushFrontList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil.

func (*List[T]) Remove added in v0.1.2

func (l *List[T]) Remove(e *ListElement[T]) T

Remove removes e from l if e is an element of list l. It returns the element value e.value. The element must not be nil.

type ListElement added in v0.1.2

type ListElement[T any] struct {

	// The value stored with this element.
	Value T
	// contains filtered or unexported fields
}

ListElement is an element of a linked list.

func (*ListElement[T]) Next added in v0.1.2

func (e *ListElement[T]) Next() *ListElement[T]

func (*ListElement[T]) Prev added in v0.1.2

func (e *ListElement[T]) Prev() *ListElement[T]

Prev returns the previous list element or nil.

type NotNullJSON

type NotNullJSON JSON

func (*NotNullJSON) Bytes

func (n *NotNullJSON) Bytes() []byte

func (*NotNullJSON) Clone

func (n *NotNullJSON) Clone() NotNullJSON

func (*NotNullJSON) Equal

func (n *NotNullJSON) Equal(o *NotNullJSON) bool

func (NotNullJSON) IsNull

func (n NotNullJSON) IsNull() bool

func (NotNullJSON) MarshalJSON

func (n NotNullJSON) MarshalJSON() ([]byte, error)

func (*NotNullJSON) Scan

func (n *NotNullJSON) Scan(value interface{}) error

func (*NotNullJSON) String

func (n *NotNullJSON) String() string

func (NotNullJSON) ToJSON added in v0.0.5

func (n NotNullJSON) ToJSON() JSON

func (*NotNullJSON) UnmarshalJSON

func (n *NotNullJSON) UnmarshalJSON(data []byte) error

func (NotNullJSON) Value

func (n NotNullJSON) Value() (driver.Value, error)

type NullInt32 added in v0.1.1

type NullInt32 sql.NullInt32

func LE0NullInt32 added in v0.1.1

func LE0NullInt32(i int32) NullInt32

LE0NullInt32 Less or Equal 0 is Null, or not Null

func NewNullInt32 added in v0.1.2

func NewNullInt32(i int32) NullInt32

func (NullInt32) Int added in v0.1.1

func (i NullInt32) Int() int32

func (NullInt32) IsAvailable added in v0.1.1

func (i NullInt32) IsAvailable() bool

func (NullInt32) IsNull added in v0.1.1

func (i NullInt32) IsNull() bool

func (NullInt32) MarshalJSON added in v0.1.1

func (i NullInt32) MarshalJSON() ([]byte, error)

func (*NullInt32) Scan added in v0.1.1

func (i *NullInt32) Scan(value any) error

func (NullInt32) String added in v0.1.1

func (i NullInt32) String() string

func (*NullInt32) UnmarshalJSON added in v0.1.1

func (i *NullInt32) UnmarshalJSON(input []byte) error

func (NullInt32) Value added in v0.1.1

func (i NullInt32) Value() (driver.Value, error)

type NullInt64 added in v0.1.1

type NullInt64 sql.NullInt64

func LE0NullInt64 added in v0.1.1

func LE0NullInt64(i int64) NullInt64

LE0NullInt64 Less or Equal to 0 is Null, or not Null

func NewNullInt64 added in v0.1.2

func NewNullInt64(i int64) NullInt64

func (*NullInt64) Clear added in v0.1.1

func (i *NullInt64) Clear()

func (NullInt64) Int added in v0.1.1

func (i NullInt64) Int() int64

func (NullInt64) IsAvailable added in v0.1.1

func (i NullInt64) IsAvailable() bool

func (NullInt64) IsNull added in v0.1.1

func (i NullInt64) IsNull() bool

func (NullInt64) MarshalJSON added in v0.1.1

func (i NullInt64) MarshalJSON() ([]byte, error)

func (*NullInt64) Scan added in v0.1.1

func (i *NullInt64) Scan(value any) error

func (*NullInt64) SetValue added in v0.1.1

func (i *NullInt64) SetValue(val int64)

func (NullInt64) String added in v0.1.1

func (i NullInt64) String() string

func (*NullInt64) UnmarshalJSON added in v0.1.1

func (i *NullInt64) UnmarshalJSON(input []byte) error

func (NullInt64) Value added in v0.1.1

func (i NullInt64) Value() (driver.Value, error)

type NullString added in v0.1.1

type NullString sql.Null[string]

func EmptyNullString added in v0.1.2

func EmptyNullString(s string) NullString

func NewNullString added in v0.1.2

func NewNullString(s string, valid bool) NullString

func (NullString) IsNull added in v0.1.1

func (n NullString) IsNull() bool

func (NullString) MarshalJSON added in v0.1.1

func (n NullString) MarshalJSON() ([]byte, error)

func (*NullString) Scan added in v0.1.1

func (n *NullString) Scan(value any) error

func (NullString) String added in v0.1.1

func (n NullString) String() string

func (*NullString) UnmarshalJSON added in v0.1.1

func (n *NullString) UnmarshalJSON(data []byte) error

func (NullString) Value added in v0.1.1

func (n NullString) Value() (driver.Value, error)

type NullTime added in v0.1.1

type NullTime sql.NullTime

func NewNullTime added in v0.1.1

func NewNullTime(t ...time.Time) NullTime

func NewNullUnixTime added in v0.1.1

func NewNullUnixTime(ut int64) NullTime

func ParseNullTime added in v0.1.2

func ParseNullTime(layout, value string) NullTime

func (NullTime) Compare added in v0.1.1

func (n NullTime) Compare(ti time.Time) int

func (NullTime) Equal added in v0.1.1

func (n NullTime) Equal(o NullTime) bool

func (NullTime) Format added in v0.1.1

func (n NullTime) Format(layout string) string

func (NullTime) IsNull added in v0.1.1

func (n NullTime) IsNull() bool

func (NullTime) MarshalJSON added in v0.1.1

func (n NullTime) MarshalJSON() ([]byte, error)

func (NullTime) Obj added in v0.1.1

func (n NullTime) Obj() time.Time

func (*NullTime) Scan added in v0.1.1

func (n *NullTime) Scan(value any) error

func (NullTime) String added in v0.1.1

func (n NullTime) String() string

func (NullTime) ToTime added in v0.1.1

func (n NullTime) ToTime() Time

func (*NullTime) UnmarshalJSON added in v0.1.1

func (n *NullTime) UnmarshalJSON(data []byte) error

func (NullTime) Value added in v0.1.1

func (n NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type OrderMap added in v0.1.2

type OrderMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

OrderMap 一个按插入顺序遍历的map,也可以通过给出的排序器顺序遍历。线程不安全。

func NewOrderMap added in v0.1.2

func NewOrderMap[K comparable, V any]() *OrderMap[K, V]

func (*OrderMap[K, V]) All added in v0.1.2

func (m *OrderMap[K, V]) All() iter.Seq2[K, V]

func (*OrderMap[K, V]) Del added in v0.1.2

func (m *OrderMap[K, V]) Del(k K)

func (*OrderMap[K, V]) Get added in v0.1.2

func (m *OrderMap[K, V]) Get(k K) (V, bool)

func (*OrderMap[K, V]) Keys added in v0.1.2

func (m *OrderMap[K, V]) Keys() iter.Seq[K]

func (*OrderMap[K, V]) Len added in v0.1.2

func (m *OrderMap[K, V]) Len() int

func (*OrderMap[K, V]) Put added in v0.1.2

func (m *OrderMap[K, V]) Put(k K, v V) *OrderMap[K, V]

type QRCodeOptions added in v0.2.0

type QRCodeOptions struct {
	Level QRCodeRecoveryLevel

	// Version accepts 0..40. 0 means auto-select the minimum valid version.
	Version int
	// Size is the output PNG width/height in pixels.
	Size int

	// LogoCover is the requested logo area ratio over QR code area.
	// When logo is present and LogoCover is 0, QRCodeDefaultLogoCover is used.
	LogoCover float64

	// recovery level to highest when logo is present.
	DisableForceHighestWhenLogo bool

	// LogoPath is an optional logo image file path.
	LogoPath string
	// LogoReader is an optional logo image reader.
	// Set either LogoPath or LogoReader, not both.
	LogoReader io.Reader
}

QRCodeOptions contains common QR generation options shared by file/writer APIs.

type QRCodeRecoveryLevel added in v0.2.0

type QRCodeRecoveryLevel int

QRCodeRecoveryLevel is the QR error correction level used by this package's public API.

type S added in v0.1.0

type S string

S is a string type with a set of convenient transformation and parsing methods.

func (S) Bytes added in v0.1.0

func (s S) Bytes() []byte

Bytes returns s as a byte slice.

func (S) CSVLike added in v0.1.0

func (s S) CSVLike() string

CSVLike wraps s with SQL LIKE wildcards for CSV column matching: "%,s,%".

func (S) CSVSplit added in v0.1.0

func (s S) CSVSplit() []string

CSVSplit splits s by commas, including Chinese comma (,) and enumeration comma (、).

func (S) CamelToSnake added in v0.1.0

func (s S) CamelToSnake() S

CamelToSnake converts CamelCase to snake_case. Consecutive uppercase letters each get their own underscore prefix.

func (S) FirstByte added in v0.1.0

func (s S) FirstByte() byte

FirstByte returns the first byte of s, or 0 if s is empty.

func (S) FirstRune added in v0.1.0

func (s S) FirstRune() rune

FirstRune returns the first Unicode code point of s, or 0 if s is empty.

func (S) FirstRuneString added in v0.1.0

func (s S) FirstRuneString() S

FirstRuneString returns the first Unicode code point of s as an S, or "" if s is empty.

func (S) Float64 added in v0.1.2

func (s S) Float64() (float64, error)

Float64 parses s as a float64 after trimming whitespace.

func (S) Formalize added in v0.1.0

func (s S) Formalize() S

Formalize returns a trimmed and lower-cased copy of s.

func (S) ID added in v0.1.0

func (s S) ID() (ID, error)

ID parses s into an ID by extracting consecutive digits. It returns an error if s contains any non-digit characters.

func (S) Includes added in v0.1.0

func (s S) Includes(ss ...string) bool

Includes reports whether s contains every non-empty string in ss.

func (S) Int64 added in v0.1.0

func (s S) Int64() (int64, error)

Int64 parses s as a base-10 int64 after trimming whitespace.

func (S) IsValid added in v0.1.0

func (s S) IsValid() bool

IsValid reports whether s is a non-empty string.

func (S) JSON added in v0.1.0

func (s S) JSON() (JSON, error)

JSON unmarshals s as JSON and returns the decoded value.

func (S) Like added in v0.1.0

func (s S) Like() string

Like wraps s with SQL LIKE wildcards: "%s%".

func (S) MustID added in v0.1.0

func (s S) MustID() ID

MustID is like ID but returns 0 on parse error instead of an error.

func (S) RegexpSplit added in v0.1.0

func (s S) RegexpSplit(expr string) ([]string, error)

RegexpSplit splits s by the regular expression expr. It returns an error if expr fails to compile.

func (S) Replace added in v0.1.0

func (s S) Replace(source, target string) S

Replace returns a new S with all non-overlapping instances of source replaced by target.

func (S) SafeSlice added in v0.2.2

func (s S) SafeSlice(maxByteLen int) string

SafeSlice truncates s to fit within maxByteLen bytes without splitting a multi-byte rune. It returns the longest prefix whose byte length does not exceed maxLen.

func (S) SplitBy added in v0.1.0

func (s S) SplitBy(sep string) []string

SplitBy splits s into substrings separated by sep.

func (S) SplitLines added in v0.1.0

func (s S) SplitLines() (SS, error)

SplitLines splits s into lines, handling both LF and CRLF line endings.

func (S) String added in v0.1.0

func (s S) String() string

String returns the underlying string value.

func (S) ToLower added in v0.1.0

func (s S) ToLower() S

ToLower returns a new S with all Unicode letters mapped to their lower case.

func (S) ToUpper added in v0.1.0

func (s S) ToUpper() S

ToUpper returns a new S with all Unicode letters mapped to their upper case.

func (S) Trim added in v0.1.0

func (s S) Trim() S

Trim returns a new S with leading and trailing whitespace removed.

type SS

type SS []string

func (SS) Append

func (ss SS) Append(s ...string) SS

func (SS) Clone

func (ss SS) Clone() SS

func (SS) Dedup

func (ss SS) Dedup(transfers ...func(input string) (string, bool)) SS

Dedup applies transfer to each element, filters out invalid values, keeps the first occurrence order, and returns a new deduplicated slice.

func (SS) DedupIn added in v0.1.4

func (ss SS) DedupIn(transfers ...func(input string) (string, bool)) SS

DedupIn applies transfer and deduplicates elements in place. It rewrites the prefix of ss with unique values in first occurrence order and returns the resulting subslice.

func (SS) Has added in v0.0.5

func (ss SS) Has(s string) bool

func (SS) Join

func (ss SS) Join(sep string) string

Join strings seperated by sep, ignoreing empty strings

func (SS) Map

func (ss SS) Map() KSet[string]

func (SS) Matchs added in v0.0.5

func (ss SS) Matchs(str string) bool

Matchs if any s in ss contained by str

func (SS) Remove

func (ss SS) Remove(strs ...string) SS

func (SS) Slice

func (ss SS) Slice() []string

func (SS) Sort added in v0.0.5

func (ss SS) Sort() SS

type StrategyFunc added in v0.3.0

type StrategyFunc = strategy.Func

StrategyFunc is a type alias for strategy.Func to maintain backwards compatibility and avoid circular dependencies between tools and strategy packages.

type Time added in v0.1.0

type Time time.Time

Time mysql timestamp precision to seconds using Now(), NewTime(), NewUnixTime() or ZeroTime() to create Time which is without monotonic clock reading (by truncating millisecond)

func NewDate added in v0.1.0

func NewDate(year int, month time.Month, day, hour, min, sec int) Time

func NewFullDate added in v0.1.0

func NewFullDate(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time

func NewTime added in v0.1.0

func NewTime(t time.Time) Time

func NewUnixTime added in v0.1.0

func NewUnixTime(ts int64) Time

func Now added in v0.1.0

func Now() Time

func ParseTime added in v0.1.2

func ParseTime(layout, value string) (Time, error)

func ZeroTime added in v0.1.0

func ZeroTime() Time

ZeroTime according to time.Time document, which is Jan 1 year 1.

func (Time) AddDate added in v0.1.2

func (t Time) AddDate(year, month, day int) Time

func (Time) After added in v0.1.0

func (t Time) After(d time.Duration) Time

func (Time) Before added in v0.1.0

func (t Time) Before(d time.Duration) Time

func (Time) Compare added in v0.1.0

func (t Time) Compare(o Time) int

func (Time) CurrentHour added in v0.1.0

func (t Time) CurrentHour() Time

func (Time) CurrentRound added in v0.1.0

func (t Time) CurrentRound(interval time.Duration) Time

func (Time) Day added in v0.1.2

func (t Time) Day() int

func (Time) DetailString added in v0.1.0

func (t Time) DetailString() string

func (Time) Equal added in v0.1.0

func (t Time) Equal(o Time) bool

func (Time) FromUnix added in v0.1.0

func (t Time) FromUnix(seconds int64) Time

func (Time) HourAfter added in v0.1.0

func (t Time) HourAfter(d time.Duration) Time

func (Time) IsZero added in v0.1.0

func (t Time) IsZero() bool

func (Time) MarshalJSON added in v0.1.0

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

func (Time) Month added in v0.1.2

func (t Time) Month() time.Month

func (Time) NNUnixMilli added in v0.1.0

func (t Time) NNUnixMilli() int64

NNUnixMilli not negetive unix milli

func (Time) NextHour added in v0.1.0

func (t Time) NextHour() Time

func (Time) NextRound added in v0.1.0

func (t Time) NextRound(interval time.Duration) Time

func (*Time) Scan added in v0.1.0

func (t *Time) Scan(value any) error

func (Time) String added in v0.1.0

func (t Time) String() string

func (Time) Sub added in v0.1.2

func (t Time) Sub(o Time) time.Duration

func (Time) Time added in v0.1.0

func (t Time) Time() time.Time

func (Time) ToDate added in v0.1.2

func (t Time) ToDate() Date

func (Time) ToNullTime added in v0.1.2

func (t Time) ToNullTime() NullTime

func (Time) UTCString added in v0.1.0

func (t Time) UTCString() string

func (Time) Unix added in v0.1.0

func (t Time) Unix() int64

func (Time) UnixMilli added in v0.1.0

func (t Time) UnixMilli() int64

func (Time) UnixMilliString added in v0.1.0

func (t Time) UnixMilliString() string

func (Time) UnixString added in v0.1.0

func (t Time) UnixString() string

func (*Time) UnmarshalJSON added in v0.1.0

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

func (Time) Value added in v0.1.0

func (t Time) Value() (driver.Value, error)

func (Time) Year added in v0.1.2

func (t Time) Year() int

type Timestamp added in v0.2.2

type Timestamp int64

func (Timestamp) DiffMillis added in v0.2.2

func (t Timestamp) DiffMillis(o Timestamp) int64

func (Timestamp) DiffSeconds added in v0.2.2

func (t Timestamp) DiffSeconds(o Timestamp) int64

func (Timestamp) IsMilli added in v0.2.2

func (t Timestamp) IsMilli() bool

func (Timestamp) ToMilliSecond added in v0.2.2

func (t Timestamp) ToMilliSecond() Timestamp

func (Timestamp) ToSecond added in v0.2.2

func (t Timestamp) ToSecond() Timestamp

func (Timestamp) ToTime added in v0.2.2

func (t Timestamp) ToTime() Time

type Version added in v0.1.1

type Version int64

Version 使用64位有符号整数,分为3部分,major.minor.patch,每部分使用6位数,最大支持999,999 patch 使用十进制最低6位数 minor 使用十进制第12位到第7位数 major 使用十进制第18位到第13位数 符号为+时,为正式版,为-时,为alpha版,0.0.0没有alpha版

func NewVersion added in v0.1.1

func NewVersion(major, minor, patch uint64, alpha bool) (Version, error)

func ParseVersion added in v0.1.1

func ParseVersion(s string) (Version, error)

func (Version) Alpha added in v0.1.1

func (v Version) Alpha() Version

func (Version) Major added in v0.1.1

func (v Version) Major() uint64

func (Version) Minor added in v0.1.1

func (v Version) Minor() uint64

func (Version) Patch added in v0.1.1

func (v Version) Patch() uint64

func (Version) String added in v0.1.1

func (v Version) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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