util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 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

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func Combination

func Combination[T any](nums []T) [][]T

Combination function: given an array, returns all combinations, e.g. (a,b,c) -> (a,b,c), (a,b), (a,c), (b,c), (a), (b), (c)

func CombinationValue

func CombinationValue(n int) int

func EachDo

func EachDo[T any](slice []T, do func(T))

func EachForGet

func EachForGet[T any, R any](slice []T, get func(i int) R) []R

func Filter

func Filter[T any](slice []T, filter func(i int) bool) []T

func Foreach

func Foreach[T any](slice []T, fn func(i int) bool)

func ForeachReverse

func ForeachReverse[T any](slice []T, fn func(i int) bool)

func MaxFn

func MaxFn[T any](aIsLarger func(current, max T) bool, args ...T) T

func Permute

func Permute[T any](nums []T) [][]T

func Range

func Range(count int, action func(i int) (stop bool))

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func Ternary

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

Types

type Flight

type Flight[V any] struct {
	// contains filtered or unexported fields
}

Flight represents one call registered with a FlightGroup.

func (*Flight[V]) Wait

func (c *Flight[V]) Wait(ctx context.Context) (value V, err error, retry bool)

Wait returns independently on caller cancellation. When retry is true, the call failed with cancellation or a deadline and the waiter is still active. The waiter should reassess its request before trying again.

type FlightGroup

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

FlightGroup tracks in-progress calls by key. Its zero value is ready to use. The caller serializes registration and completion with the same lock, so it can coordinate both with external state such as a cache. Wait outside that lock.

func (*FlightGroup[K, V]) FinishLocked

func (g *FlightGroup[K, V]) FinishLocked(key K, call *Flight[V], value V, err error)

FinishLocked removes the leader's call for key and publishes its result to waiters. Pass the call returned by JoinOrStartLocked for that key. The value may be shared with multiple waiters and must be safe to share.

func (*FlightGroup[K, V]) JoinOrStartLocked

func (g *FlightGroup[K, V]) JoinOrStartLocked(key K) (call *Flight[V], leader bool)

JoinOrStartLocked joins a pending call or registers a new one. The caller that receives leader=true performs the work and must finish the call once.

type MySQLVersion

type MySQLVersion struct {
	MySQLDBType int // 1 is MySQL, 2 is MariaDB
	Major       int
	Minor       int
	Patch       int
}

func ParseVersion

func ParseVersion(versionString string) MySQLVersion

func (*MySQLVersion) BeforeMySQL57

func (mv *MySQLVersion) BeforeMySQL57() bool

BeforeMySQL57 reports whether mv is a known MySQL release older than 5.7. MariaDB and unknown or invalid versions return false so callers keep the MySQL 5.7/8.0 behavior.

func (*MySQLVersion) GEV8

func (mv *MySQLVersion) GEV8() bool

GEV8 : version >= MySQL8

func (*MySQLVersion) IsMariaDB

func (mv *MySQLVersion) IsMariaDB() bool

func (*MySQLVersion) IsMySQL

func (mv *MySQLVersion) IsMySQL() bool

func (*MySQLVersion) IsValid

func (mv *MySQLVersion) IsValid() bool

type VersionSemantic

type VersionSemantic int
const (
	VersionMajor VersionSemantic = 0
	VersionMinor VersionSemantic = 1
	VersionPatch VersionSemantic = 2
)

Jump to

Keyboard shortcuts

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