util

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Default File Mode
	DefFileMode = 0666

	GbUnit uint64 = MbUnit * 1024
	MbUnit uint64 = KbUnit * 1024
	KbUnit uint64 = 1024
)
View Source
const (
	LoopbackLocalHost = "localhost"
	Loopback127       = "127.0.0.1"
	LocalIpAny        = "0.0.0.0"
)
View Source
const (
	ClassicDateTimeLocaleFormat = "2006/01/02 15:04:05 (MST)"
	ClassicDateTimeFormat       = "2006/01/02 15:04:05"
	StdDateTimeFormat           = "2006-01-02 15:04:05"
	StdDateTimeMilliFormat      = "2006-01-02 15:04:05.000"
	StdDateTimeLocaleFormat     = "2006-01-02 15:04:05 (MST)"
	SQLDateTimeFormat           = "2006-01-02 15:04:05.999999"
	SQLDateTimeFormatWithT      = "2006-01-02T15:04:05.999999"
	SQLDateFormat               = "2006-01-02"
)
View Source
const (
	DEFAULT_LEN = 35
)

Variables

View Source
var (
	ErrGetTimeout = errors.New("future.TimedGet timeout")
)
View Source
var (
	Printlnf = cli.Printlnf
)
View Source
var (
	ToETime = WrapTime
)

Functions

func AddETimeParseFormat added in v0.1.21

func AddETimeParseFormat(fmt ...string)

func AppendableFile

func AppendableFile(name string) (*os.File, error)

Create appendable file with 0666 permission.

func CallerRunTaskWhenPoolFull added in v0.2.2

func CallerRunTaskWhenPoolFull() asyncPoolOption

func CpuProfileFunc added in v0.1.13

func CpuProfileFunc(file string, fu func()) error

func DropTaskWhenPoolFull added in v0.2.2

func DropTaskWhenPoolFull() asyncPoolOption

func ERand

func ERand(len int) string

Generate random string with high entrophy

func EscapeString added in v0.1.13

func EscapeString(s string) string

Escape String

Acknowledgement: following code is copied from https://github.com/pingcap/tidb/blob/master/pkg/util/sqlescape/utils.go (Copyright 2021 PingCAP, Inc. Apache License)

func FileAddSuffix added in v0.2.0

func FileAddSuffix(name string, ext string) string

func FileChangeSuffix added in v0.2.11

func FileChangeSuffix(name string, newSuffix string) (s string)

func FileCutDotSuffix added in v0.2.8

func FileCutDotSuffix(name string) (s string, suffix string, ok bool)

func FileCutSuffix added in v0.1.27

func FileCutSuffix(name string, ext string) (string, bool)

func FileExists

func FileExists(path string) (bool, error)

Check if file exists

func FileHasAnySuffix added in v0.2.0

func FileHasAnySuffix(name string, ext ...string) bool

func FileHasSuffix added in v0.1.27

func FileHasSuffix(name string, ext string) bool

func FindTestdata added in v0.2.8

func FindTestdata(t *testing.T, relativePath string) string

func FixedPoolFilterFunc added in v0.1.21

func FixedPoolFilterFunc[T any](filterFunc func(t T) (dropped bool)) func(*FixedPool[T])

func FuzzParseTime

func FuzzParseTime(formats []string, value string) (time.Time, error)

func FuzzParseTimeLoc added in v0.1.1

func FuzzParseTimeLoc(formats []string, value string, loc *time.Location) (time.Time, error)

func GenId deprecated

func GenId() (id string)

Generate Snowflake Id.

The id consists of 64 bits long + 6 digits machine_code. The 64 bits long consists of: sign bit (1 bit) + timestamp (49 bits, ~1487.583 years) + sequenceNo (14 bits, 0~16383).

The max value of Long is 9223372036854775807, which is a string with 19 characters, so the generated id will be of at most 25 characters.

This func is thread-safe.

Deprecated: Use [idutil.New] instead.

func GenIdP deprecated

func GenIdP(prefix string) (id string)

Generate Snowflake Id with extra prefix.

The id consists of 64 bits long + 6 digits machine_code. The 64 bits long consists of: sign bit (1 bit) + timestamp (49 bits, ~1487.583 years) + sequenceNo (14 bits, 0~16383).

The max value of Long is 9223372036854775807, which is a string with 19 characters, so the generated id will be of at most 25 characters.

This func is thread-safe.

Deprecated: Use [idutil.Id] instead.

func GenNo

func GenNo(prefix string) string

generate a random sequence number with specified prefix

func GenNoL

func GenNoL(prefix string, len int) string

generate a random sequence number with specified prefix

func GetLocalIPV4 added in v0.1.8

func GetLocalIPV4() string

Get local ipv4 address (excluding loopback address)

func IsLocalAddress added in v0.1.8

func IsLocalAddress(address string) bool

Check whether the address is local (localhost/127.0.0.1)

func IsVoid

func IsVoid(t reflect.Type) bool

func MaxInt

func MaxInt(a int, b int) int

func MemoryProfileFunc added in v0.1.13

func MemoryProfileFunc(file string, fu func()) error

func MinInt

func MinInt(a int, b int) int

func MkdirAll

func MkdirAll(path string) error

MkdirAll with 0755 perm.

func MkdirParentAll

func MkdirParentAll(path string) error

MkdirAll but only for the parent directory of the path, perm 0755 is used.

The path should always point to a specific file under some directories, as this method always attempts to extract parent dir of the file. It the path fails to fulfill this requirement, the output might be unexpected.

func MkdirTree added in v0.3.2

func MkdirTree(t DirTree) error

func Must added in v0.1.4

func Must(err error)

func MustGet added in v0.1.11

func MustGet[V any](v V, err error) V

func NewSubmitAsyncFunc

func NewSubmitAsyncFunc[T any](pool AsyncPoolItf) func(task func() (T, error)) Future[T]

Create func that calls SubmitAsync(...) with the given pool.

func OpenFile

func OpenFile(name string, flag int) (*os.File, error)

Open file with 0666 permission.

func OpenRFile added in v0.1.27

func OpenRFile(name string) (*os.File, error)

Open readable file with 0666 permission.

func OpenRWFile added in v0.1.27

func OpenRWFile(name string, createIfAbsent bool) (*os.File, error)

Open readable & writable file with 0666 permission.

func PanicSafeErrFunc added in v0.3.2

func PanicSafeErrFunc(op func() error) func() error

func PanicSafeFunc added in v0.1.1

func PanicSafeFunc(op func()) func()

func PanicSafeRun added in v0.2.4

func PanicSafeRun(op func())

func PanicSafeRunErr added in v0.3.2

func PanicSafeRunErr(op func() error) error

func ParseClassicDateTime added in v0.1.1

func ParseClassicDateTime(val string, loc *time.Location) (time.Time, error)

Parse classic datetime format using patterns: "2006-01-02 15:04:05", "2006/01/02 15:04:05".

func Pick

func Pick(set []rune) rune

pick random rune from the slice

func RandAlpha

func RandAlpha(n int) string

Generate random alphabetic string with specified length

the generated string will contains [a-zA-Z]

func RandLowerAlpha

func RandLowerAlpha(n int) string

Generate random alphabetic, lowercase string with specified length

the generated string will contains [a-z]

func RandLowerAlphaNumeric

func RandLowerAlphaNumeric(n int) string

Generate random alphabetic, lowercase string with specified length

the generated string will contains [a-z0-9]

func RandLowerAlphaNumeric16

func RandLowerAlphaNumeric16() string

Same as RandLowerAlphaNumeric(16) but with less allocation.

func RandNum

func RandNum(n int) string

Generate random numeric string with specified length

the generated string will contains [0-9]

func RandOp added in v0.1.11

func RandOp(ops ...func())

invoke one of the funcs randomly

func RandPick added in v0.1.11

func RandPick[T any](s []T) T

func RandRune added in v0.1.6

func RandRune(n int, set []rune) string

generate randon str based on given length and given charset

func RandStr

func RandStr(n int) string

Generate random string with specified length

the generated string will contains [a-zA-Z0-9]

ERand() is preferred for higher entrophy

func RandUpperAlpha

func RandUpperAlpha(n int) string

Generate random alphabetic, uppercase string with specified length

the generated string will contains [A-Z]

func RandUpperAlphaNumeric

func RandUpperAlphaNumeric(n int) string

Generate random alphabetic, uppercase string with specified length

the generated string will contains [A-Z0-9]

func ReadFileAll

func ReadFileAll(path string) ([]byte, error)

Read all content from file.

func ReadWriteFile

func ReadWriteFile(name string) (*os.File, error)

Create readable & writable file with 0666 permission.

If file is missing, new empty file is created.

func SaveTmpFile added in v0.1.1

func SaveTmpFile(tmpDir string, reader io.Reader) (string, error)

Save to temp file, returns temp file path or error.

func SetETimeMarshalFormat added in v0.1.19

func SetETimeMarshalFormat(fmt string)

func SetMachineCode

func SetMachineCode(code int) error

Overwrite the randomly generated machine code, machine code must be between 0 and 999999, at most 6 digits.

func ShuffleRunes

func ShuffleRunes(letters []rune, times int) []rune

func ShuffleStr

func ShuffleStr(letters string, times int) string

func SnowflakeId added in v0.2.8

func SnowflakeId() (id string)

Generate Snowflake Id

The id consists of [64 bits long] + [6 digits machine_code] The 64 bits long consists of: [sign bit (1 bit)] + [timestamp (49 bits, ~1487.583 years)] + [sequenceNo (14 bits, 0~16383)]

The max value of Long is 9223372036854775807, which is a string with 19 characters, so the generated id will be of at most 25 characters

This func is thread-safe

func StrByteLen added in v0.1.14

func StrByteLen(s string) int

Get string's length in bytes

func TempFile added in v0.2.1

func TempFile() (*os.File, error)

func TempFilePath added in v0.2.1

func TempFilePath() (string, error)

func TempFilePathSuffix added in v0.2.6

func TempFilePathSuffix(suffix string) (string, error)

func TempFileSuffix added in v0.2.6

func TempFileSuffix(suffix string) (*os.File, error)

func TryFileExists added in v0.2.2

func TryFileExists(path string) bool

Check if file exists without returning error.

This is mainly a lazy version of FileExists(), it's not recommended for most cases.

func UnsafeByt2Str

func UnsafeByt2Str(b []byte) string

Convert []byte to string without alloc.

Both the []byte and the string share the same memory.

Any modification on the original []byte is reflected on the returned string.

byt = []byte("abc")
s = UnsafeByt2Str(byt) // "abc" using the same memory
byt[0] = 'd' // modified in place at 0, also reflected on s ("dbc")

Tricks from https://github.com/valyala/fasthttp and https://go101.org/article/unsafe.html

See: https://github.com/golang/go/issues/53003

func UnsafeStr2Byt

func UnsafeStr2Byt(s string) (b []byte)

Convert string to []byte without alloc.

Both the []byte and the string share the same memory.

The resulting []byte is not modifiable, program will panic if modified.

s := "abc"
byt := UnsafeStr2Byt(s) // "abc" but in []byte
byt[0] = 'd' // will panic

Tricks from https://github.com/valyala/fasthttp and https://go101.org/article/unsafe.html

See: https://github.com/golang/go/issues/53003

func WeightedRandPick added in v0.1.11

func WeightedRandPick[T interface{ GetWeight() float64 }](s []T) T

Types

type AntsAsyncPool added in v0.2.10

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

func (*AntsAsyncPool) Go added in v0.2.10

func (a *AntsAsyncPool) Go(f func()) error

func (*AntsAsyncPool) Stop added in v0.2.10

func (a *AntsAsyncPool) Stop()

func (*AntsAsyncPool) StopAndWait added in v0.2.10

func (a *AntsAsyncPool) StopAndWait()

type AsyncPool

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

A long live, bounded pool of goroutines.

Use miso.NewAsyncPool to create a new pool.

AsyncPool internally maintains a task queue with limited size and limited number of workers.

By default, if the task queue is full and all workers are busy, the caller of *AsyncPool.Go is blocked indefinitively until the task can be processed. You can use DropTaskWhenPoolFull or CallerRunTaskWhenPoolFull to change this behaviour.

func NewAsyncPool

func NewAsyncPool(maxTasks int, maxWorkers int, opts ...asyncPoolOption) *AsyncPool

Create a bounded pool of goroutines.

The maxTasks determines the capacity of the task queues.

The maxWorkers determines the max number of workers.

By default, if the task queue is full and all workers are busy, the caller of *AsyncPool.Go is blocked indefinitively until the task can be processed. You can use DropTaskWhenPoolFull or CallerRunTaskWhenPoolFull to change this behaviour.

func (*AsyncPool) Go

func (p *AsyncPool) Go(f func()) error

Submit task to the pool.

If the pool is closed, caller will execute the submitted task directly.

func (*AsyncPool) Stop added in v0.1.10

func (p *AsyncPool) Stop()

Stop the pool.

Once the pool is stopped, new tasks submitted are executed directly by the caller.

func (*AsyncPool) StopAndWait added in v0.1.10

func (p *AsyncPool) StopAndWait()

Stop the pool and wait until existing workers drain all the remaining tasks.

Once the pool is stopped, new tasks submitted are executed directly by the caller.

type AsyncPoolItf added in v0.2.10

type AsyncPoolItf interface {
	Go(f func()) error
	Stop()
	StopAndWait()
}

func NewAntsAsyncPool added in v0.2.10

func NewAntsAsyncPool(maxWorkers int, opts ...asyncPoolOption) AsyncPoolItf

Create a bounded pool of goroutines.

The maxTasks determines the capacity of the task queues.

The maxWorkers determines the max number of workers.

By default, if the task queue is full and all workers are busy, the caller of AsyncPoolItf.Go() is blocked indefinitively until the task can be processed. You can use DropTaskWhenPoolFull or CallerRunTaskWhenPoolFull to change this behaviour.

func NewCpuAsyncPool added in v0.1.11

func NewCpuAsyncPool() AsyncPoolItf

Create AsyncPool with number of workers equals to 4 * num_cpu.

func NewIOAsyncPool added in v0.1.11

func NewIOAsyncPool() AsyncPoolItf

Create AsyncPool with number of workers equals to 8 * num_cpu and a task queue of size 500.

type AwaitFutures

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

AwaitFutures represent tasks that are submitted to the pool asynchronously whose results are awaited together.

AwaitFutures should only be used once for the same group of tasks.

Use miso.NewAwaitFutures() to create one.

func NewAwaitFutures

func NewAwaitFutures[T any](pool AsyncPoolItf) *AwaitFutures[T]

Create new AwaitFutures for a group of tasks.

*AsyncPool is optional, provide nil if not needed.

func (*AwaitFutures[T]) Await

func (a *AwaitFutures[T]) Await() []Future[T]

Await results of all tasks.

func (*AwaitFutures[T]) AwaitAnyErr added in v0.1.2

func (a *AwaitFutures[T]) AwaitAnyErr() error

Await results of all tasks and return any error that is found in the task Futures.

func (*AwaitFutures[T]) AwaitResultAnyErr added in v0.2.0

func (a *AwaitFutures[T]) AwaitResultAnyErr() ([]T, error)

Await results of all tasks and return any error that is found in the task Futures.

func (*AwaitFutures[T]) SubmitAsync

func (a *AwaitFutures[T]) SubmitAsync(task func() (T, error))

Submit task to AwaitFutures.

type BasicValue added in v0.2.0

type BasicValue interface {
	Complex | Number | ~string | ~bool
}

type BatchTask added in v0.1.16

type BatchTask[T any, V any] struct {
	// contains filtered or unexported fields
}

func NewBatchTask added in v0.1.16

func NewBatchTask[T any, V any](parallel int, bufferSize int, consumer func(T) (V, error)) *BatchTask[T, V]

Create a batch of concurrent task for one time use.

func (*BatchTask[T, V]) Close added in v0.1.16

func (b *BatchTask[T, V]) Close()

Close underlying pipeline channel without waiting.

func (*BatchTask[T, V]) Generate added in v0.1.16

func (b *BatchTask[T, V]) Generate(task T)

Generate task.

func (*BatchTask[T, V]) Wait added in v0.1.16

func (b *BatchTask[T, V]) Wait() []BatchTaskResult[V]

Wait until all generated tasks are completed and close pipeline channel.

type BatchTaskResult added in v0.1.19

type BatchTaskResult[V any] struct {
	Result V
	Err    error
}

type ByteBufPool added in v0.1.2

type ByteBufPool struct {
	MaxCap int // default max cap is 4096 bytes.
	// contains filtered or unexported fields
}

func NewByteBufferPool added in v0.1.2

func NewByteBufferPool(initCap int) *ByteBufPool

func (*ByteBufPool) Get added in v0.1.2

func (b *ByteBufPool) Get() *bytes.Buffer

func (*ByteBufPool) Put added in v0.1.2

func (b *ByteBufPool) Put(buf *bytes.Buffer)

type Complex added in v0.2.0

type Complex interface {
	~complex64 | ~complex128
}

type Consumer added in v0.1.4

type Consumer[T any] func(t T) error

Consume t

type Converter added in v0.1.4

type Converter[T any, V any] func(t T) (V, error)

Convert t to v

type DirTree added in v0.3.2

type DirTree struct {
	Name      string
	Childs    []DirTree
	IsFile    bool
	OnCreated func(f *os.File) error
	Skip      bool
}

type ETime

type ETime = Time

func MayParseETime added in v0.1.25

func MayParseETime(v any) ETime

func MayParseETimeLoc added in v0.2.0

func MayParseETimeLoc(v any, loc *time.Location) ETime

func ParseETime added in v0.1.24

func ParseETime(v any) (ETime, error)

func ParseETimeLoc added in v0.2.0

func ParseETimeLoc(v any, loc *time.Location) (ETime, error)

func (*ETime) Scan

func (et *ETime) Scan(value interface{}) error

Implements sql.Scanner in database/sql.

func (*ETime) ScanLoc added in v0.2.0

func (et *ETime) ScanLoc(value interface{}, loc *time.Location) error

type FixedPool added in v0.1.21

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

func NewFixedPool added in v0.1.21

func NewFixedPool[T any](cap int, options ...func(*FixedPool[T])) *FixedPool[T]

func (*FixedPool[T]) Pop added in v0.1.21

func (r *FixedPool[T]) Pop() (T, bool)

func (*FixedPool[T]) Push added in v0.1.21

func (r *FixedPool[T]) Push(t T)

func (*FixedPool[T]) TryPop added in v0.1.21

func (r *FixedPool[T]) TryPop() (T, bool)

func (*FixedPool[T]) TryPush added in v0.1.21

func (r *FixedPool[T]) TryPush(t T) bool

type Float added in v0.2.0

type Float interface {
	~float32 | ~float64
}

type Future

type Future[T any] interface {

	// Get result without timeout.
	Get() (T, error)

	// Get result with timeout, returns ErrGetTimeout if timeout exceeded.
	TimedGet(timeout int) (T, error)

	// Then callback to be invoked when the Future is completed.
	//
	// Then callback should only be set once for every Future.
	Then(tf func(T, error))
}

Result of a asynchronous task.

func NewCompletedFuture added in v0.1.25

func NewCompletedFuture[T any](t T, err error) Future[T]

func RunAsync

func RunAsync[T any](task func() (T, error)) Future[T]

Create Future, once the future is created, it starts running on a new goroutine.

func SubmitAsync

func SubmitAsync[T any](pool AsyncPoolItf, task func() (T, error)) Future[T]

Create Future, once the future is created, it starts running on a saperate goroutine from the pool.

type Integer added in v0.2.0

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Number added in v0.2.0

type Number interface {
	Float | Integer
}

type Peek added in v0.1.4

type Peek[T any] func(t T)

Peek t

type Predicate added in v0.1.4

type Predicate[T any] func(t T) bool

Predicate based on t

type SignalOnce added in v0.1.13

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

func NewSignalOnce added in v0.1.13

func NewSignalOnce() *SignalOnce

func (*SignalOnce) Closed added in v0.1.13

func (s *SignalOnce) Closed() bool

func (*SignalOnce) Notify added in v0.1.13

func (s *SignalOnce) Notify()

func (*SignalOnce) TimedWait added in v0.1.13

func (s *SignalOnce) TimedWait(timeout time.Duration) (isTimeout bool)

func (*SignalOnce) Wait added in v0.1.13

func (s *SignalOnce) Wait()

type Supplier added in v0.1.4

type Supplier[T any] func() T

Supplier of T

type Time added in v0.3.1

type Time struct {
	time.Time
}

Enhanced wrapper of time.Time.

This type implements sql.Scanner and driver.Valuer, it can be safely used in GORM just like time.Time.

It also implements json/encoding Marshaler and Unmarshaler to support json marshalling.

In previous releases, Time was a type alias to time.Time. Since v0.1.2, Time embeds time.Time to access all of it's methods.

To cast from time.Time to Time, use WrapTime method. To cast from Time to time.Time, use Time.Unwrap method.

By default, Time support following unmarshaling formats:

  • time.RFC3339
  • time.RFC3339Nano
  • 2006-01-02 15:04:05.999999
  • 2006-01-02
  • 2006-01-02T15:04:05.999999
  • millseconds since unix epoch
  • seconds since unix epoch

By default, Time is marshaled as millseconds since unix epoch. You can change this behaviour though SetETimeMarshalFormat.

func Now

func Now() Time

func NowPtr added in v0.2.0

func NowPtr() *Time

func NowUTC added in v0.2.0

func NowUTC() Time

func NowUTCPtr added in v0.2.0

func NowUTCPtr() *Time

func WrapTime added in v0.3.1

func WrapTime(t time.Time) Time

func (Time) Add added in v0.3.1

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

func (Time) AddDate added in v0.3.1

func (t Time) AddDate(years int, months int, days int) Time

func (Time) After added in v0.3.1

func (t Time) After(u Time) bool

func (Time) Before added in v0.3.1

func (t Time) Before(u Time) bool

func (Time) EndOfDay added in v0.3.1

func (t Time) EndOfDay() Time

At 23:59:59.999999.

func (Time) EndOfMonth added in v0.3.2

func (t Time) EndOfMonth() Time

func (Time) FormatClassic added in v0.3.1

func (t Time) FormatClassic() string

Format as 2006/01/02 15:04:05

func (Time) FormatClassicLocale added in v0.3.1

func (t Time) FormatClassicLocale() string

Format as 2006/01/02 15:04:05 (MST)

func (Time) FormatDate added in v0.3.1

func (t Time) FormatDate() string

Format as 2006-01-02

func (Time) FormatRFC3339 added in v0.3.2

func (t Time) FormatRFC3339() string

Format as time.RFC3339

func (Time) FormatRFC3339Nano added in v0.3.2

func (t Time) FormatRFC3339Nano() string

Format as time.RFC3339Nano

func (Time) FormatStd added in v0.3.1

func (t Time) FormatStd() string

Format as 2006-01-02 15:04:05

func (Time) FormatStdLocale added in v0.3.1

func (t Time) FormatStdLocale() string

Format as 2006-01-02 15:04:05 (MST)

func (Time) FormatStdMilli added in v0.3.1

func (t Time) FormatStdMilli() string

Format as 2006-01-02 15:04:05.000

func (Time) GoString added in v0.3.1

func (t Time) GoString() string

func (Time) In added in v0.3.1

func (t Time) In(z *time.Location) Time

func (Time) InZone added in v0.3.1

func (t Time) InZone(diffInHours int) Time

func (Time) LastWeekday added in v0.3.1

func (t Time) LastWeekday(w time.Weekday) Time

func (Time) MarshalJSON added in v0.3.1

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

Implements encoding/json Marshaler

func (Time) NextWeekday added in v0.3.1

func (t Time) NextWeekday(w time.Weekday) Time

func (Time) StartOfDay added in v0.3.1

func (t Time) StartOfDay() Time

At 00:00:00.000000.

func (Time) StartOfMonth added in v0.3.2

func (t Time) StartOfMonth() Time

func (Time) String added in v0.3.1

func (t Time) String() string

func (Time) Sub added in v0.3.1

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

func (Time) ToTime deprecated added in v0.3.1

func (t Time) ToTime() time.Time

Deprecated: change to Time.Unwrap.

func (*Time) UnmarshalJSON added in v0.3.1

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

Implements encoding/json Unmarshaler.

func (Time) Unwrap added in v0.3.1

func (t Time) Unwrap() time.Time

func (Time) Value added in v0.3.1

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

Implements driver.Valuer in database/sql.

type Transform added in v0.1.4

type Transform[T any] func(t T) T

Transform t to another t

type TransformAsync added in v0.1.16

type TransformAsync[T any] func(t T) Future[T]

Transform t to another t

type Void

type Void struct{}

Empty Struct

type WalkFsFile added in v0.2.6

type WalkFsFile struct {
	Path string
	File fs.FileInfo
}

func WalkDir added in v0.2.6

func WalkDir(n string, suffix ...string) ([]WalkFsFile, error)

type WeightedItem added in v0.1.11

type WeightedItem[T any] struct {
	Value  T
	Weight float64
}

func (WeightedItem[T]) GetWeight added in v0.1.11

func (w WeightedItem[T]) GetWeight() float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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