util

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t *testing.T, except, actual interface{}, msg string)

func AssertEqualJson

func AssertEqualJson(t *testing.T, except, actual string)

func AssertEqualString

func AssertEqualString(t *testing.T, except, actual, msg string)

func Bytes2str added in v0.0.10

func Bytes2str(b *[]byte) string

cast `[]byte` to string by zero-copy, caller should to ensure the `b` will NOT be changed in the subsequent processes refer: https://github.com/golang/go/blob/a6219737e3eb062282e6483a915c395affb30c69/src/strings/builder.go#L48

func CloneMap

func CloneMap[T1 comparable, T2 any](m map[T1]T2) map[T1]T2

func Copy

func Copy[T any](arr []T) []T

func Download

func Download(url, dist string) error

func FileExist

func FileExist(file string) bool

func FlattenMap

func FlattenMap(m map[string]interface{}) map[string]interface{}

func GetByPath

func GetByPath(obj map[string]interface{}, path []string) interface{}

func Includes

func Includes[T comparable](arr []T, v T) bool

func IsDir

func IsDir(file string) bool

func IsFile

func IsFile(file string) bool

func IsNilPtr

func IsNilPtr(v interface{}) bool

func JsonToKeyPathAndVal

func JsonToKeyPathAndVal(jsonStr string) (map[string]interface{}, error)

func Keys

func Keys[K comparable, V any](m map[K]V) []K

func Merge

func Merge[T1 comparable, T2 any](src, stuff map[T1]T2)

func MergeMap

func MergeMap(dst map[string]interface{}, src map[string]interface{})

func MergeMaps

func MergeMaps(dst map[string]interface{}, src ...map[string]interface{})

func PickOne

func PickOne[T1 comparable, T2 any](sets map[T1]T2) (v T2)

func PickOnePair

func PickOnePair[T1 comparable, T2 any](sets map[T1]T2) (k T1, v T2)

func RemoveAt

func RemoveAt[T any](arr *[]T, i int)

move the targe elem to the tail of the slice then do the pop so this method will change the order of the origin slide

func RemoveJsonComments

func RemoveJsonComments(str string) ([]byte, error)

remove comments in json, for keeping the loc of error is meaningful, the comments are replaced with their equal-length spaces

func Shell

func Shell(command string, args ...string)

func ShellInDir

func ShellInDir(dir, command string, args ...string)

func Swap

func Swap[T any](arr []T, i, j int)

exchange the elems at position `i` and `j`

func TakeOne

func TakeOne[T1 comparable, T2 any](sets map[T1]T2) (v T2)

func UnTarGz

func UnTarGz(tarball, dist string) error

func WalkObj

func WalkObj(obj interface{}, path []string, cb WalkObjFn, key interface{}, parent interface{}, arr bool) bool

Types

type DirWalker

type DirWalker struct {
	Dir        string
	Concurrent int
	// contains filtered or unexported fields
}

by the benchmark, there is no execution performance benefit from the works pool, however the works pool is still useful since it can stop the routine more precisely

func NewDirWalker

func NewDirWalker(dir string, concurrent int, handle DirWalkerHandle) *DirWalker

func (*DirWalker) Err

func (w *DirWalker) Err() error

func (*DirWalker) Stop

func (w *DirWalker) Stop(err error)

func (*DirWalker) Walk

func (w *DirWalker) Walk()

type DirWalkerHandle

type DirWalkerHandle = func(string, bool, *DirWalker)

type KvPair

type KvPair[K comparable, V any] struct {
	Key K
	Val V
}

type LruCache

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

func NewLruCache

func NewLruCache[K comparable, V any](cap int, clear int) *LruCache[K, V]

- cap, the capacity of the store, normally the max number elements can be stored - clear, the number of elements to be cleared when the store is full, default is 1/3 of capacity

func (*LruCache[K, V]) Get

func (c *LruCache[K, V]) Get(key K) V

func (*LruCache[K, V]) HasKey

func (c *LruCache[K, V]) HasKey(key K) bool

func (*LruCache[K, V]) Set

func (c *LruCache[K, V]) Set(key K, val V)

type OrderedMap

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

func NewOrderedMap

func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]

func (*OrderedMap[k, v]) Front

func (o *OrderedMap[k, v]) Front() *list.Element

func (*OrderedMap[K, V]) Get

func (o *OrderedMap[K, V]) Get(key K) (v V)

func (*OrderedMap[K, V]) HasKey

func (o *OrderedMap[K, V]) HasKey(key K) bool

func (*OrderedMap[k, v]) Remove

func (o *OrderedMap[k, v]) Remove(key k)

func (*OrderedMap[K, V]) Set

func (o *OrderedMap[K, V]) Set(key K, val V) *list.Element

type WalkObjFn

type WalkObjFn func(path []string, val interface{}, key interface{}, parent interface{}, arr bool) bool

Jump to

Keyboard shortcuts

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