gutil

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: BSD-3-Clause Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KiB = 1 << 10
	MiB = 1 << 20
	GiB = 1 << 30
	TiB = 1 << 40
)

Variables

View Source
var EssentialProjDirs = []string{"bin", "config", "data", "logs"}

Functions

func CatchPanic added in v1.0.10

func CatchPanic(title string)

func CopyFile

func CopyFile(dest, source string) error

CopyFile writes the contents of the given source file to dest.

func GetCallStackNames added in v1.0.10

func GetCallStackNames(skip, limit int) []string

GetCallStackNames 当前调用栈得名称

func GetEnv

func GetEnv(key string, def string) string

GetEnv 获取环境变量

func GetEnvBool

func GetEnvBool(key string) bool

GetEnvBool 获取环境变量bool值

func GetEnvFloat

func GetEnvFloat(key string, def float64) float64

GetEnvFloat 获取环境变量float值

func GetEnvInt

func GetEnvInt(key string, def int) int

GetEnvInt 获取环境变量int值

func GetEnvInt64

func GetEnvInt64(key string, def int64) int64

func GetProjRootDir

func GetProjRootDir() string

func GetProjRootDirOf

func GetProjRootDirOf(path string) string

func IsFileExist

func IsFileExist(filename string) bool

IsFileExist test if file exist

func IsFileNotExist

func IsFileNotExist(filename string) bool

func IsProjRootDir

func IsProjRootDir(path string) bool

IsProjRootDir 如果有以下几个目录,就认为是项目的根路径

func JSONParse

func JSONParse(s string, v any) error

JSONParse 避免大数值被解析为float导致的精度丢失

func JSONStringify

func JSONStringify(v any) string

JSONStringify 序列化为json字符串

func LoadDotEnv

func LoadDotEnv(filenames ...string) error

func MD5Sum

func MD5Sum(data []byte) string

MD5Sum 计算MD5值

func MapAdd added in v1.0.10

func MapAdd[M ~map[K]V, K comparable, V cmp.Ordered](a, b M) M

MapAdd 把b的所有值加到a里

func MapIntersect added in v1.0.10

func MapIntersect[M ~map[K]V, K, V comparable](a, b M) M

MapIntersect 返回两个map的交集, a ∩ b

func MapKeyValues added in v1.0.10

func MapKeyValues[M ~map[K]V, K comparable, V any](m M) ([]K, []V)

MapKeyValues 返回map的key和value列表

func MapKeys added in v1.0.10

func MapKeys[M ~map[K]V, K comparable, V any](m M) []K

MapKeys 返回map的key列表

func MapOrderedKeyValues added in v1.0.10

func MapOrderedKeyValues[M ~map[K]V, K cmp.Ordered, V any](m M) ([]K, []V)

MapOrderedKeyValues 返回map里已排序的key和value列表

func MapOrderedKeys added in v1.0.10

func MapOrderedKeys[M ~map[K]V, K cmp.Ordered, V any](m M) []K

MapOrderedKeys 返回map里已排序的key列表

func MapOrderedValues added in v1.0.10

func MapOrderedValues[M ~map[K]V, K cmp.Ordered, V any](m M) []V

MapOrderedValues 返回map里按key排序的value列表

func MapUnion added in v1.0.10

func MapUnion[M ~map[K]V, K comparable, V any](a, b M) M

MapUnion 返回两个map的并集, copy of a ∪ b

func MapValues added in v1.0.10

func MapValues[M ~map[K]V, K comparable, V any](m M) []V

MapValues 返回map的value列表

func MarshalProtoJSON added in v1.0.10

func MarshalProtoJSON(msg proto.Message) ([]byte, error)

MarshalProtoJSON 序列化proto消息为json格式

func ParseByteCount

func ParseByteCount(s string) (int64, bool)

ParseByteCount parses a string that represents a count of bytes. suffixes include B, KiB, MiB, GiB, and TiB represent quantities of bytes as defined by the IEC 80000-13 standard

func PrettyBytes

func PrettyBytes(nbytes int64) string

PrettyBytes 打印容量大小

func ReadFileToLines

func ReadFileToLines(filename string) ([]string, error)

ReadFileToLines 把文件内容按一行一行读取

func ReadGCPercent added in v1.0.10

func ReadGCPercent() uint64

ReadGCPercent see https://pkg.go.dev/runtime/debug#SetGCPercent

func ReadMemoryLimit added in v1.0.10

func ReadMemoryLimit() string

ReadMemoryLimit see https://pkg.go.dev/runtime/debug#SetMemoryLimit

func ReadMetrics added in v1.0.10

func ReadMetrics(category string) map[string]any

ReadMetrics 读取指定的metrics see https://pkg.go.dev/runtime/metrics

func ReadToLines

func ReadToLines(rd io.Reader) ([]string, error)

ReadToLines 把内容按行读取

func SHA1Sum

func SHA1Sum(data []byte) string

SHA1Sum 计算SHA1值

func SHA256Sum

func SHA256Sum(data []byte) string

SHA256Sum 计算SHA256值

func StartProfiler added in v1.0.10

func StartProfiler(addr string)

func TraceStack added in v1.0.10

func TraceStack(skip int, title string, err interface{}, w io.Writer)

func UnmarshalProtoJSON added in v1.0.10

func UnmarshalProtoJSON(b []byte, m proto.Message) error

func ZeroOf added in v1.0.10

func ZeroOf[T any]() T

ZeroOf returns the zero value of the type T

Types

type CSVTable added in v1.0.10

type CSVTable struct {
	Header map[string]int
	Rows   [][]string
}

CSVTable represents a CSV table

func NewCSVRecords added in v1.0.10

func NewCSVRecords() *CSVTable

func ReadCSVTable added in v1.0.10

func ReadCSVTable(filename string) (*CSVTable, error)

ReadCSVTable 从csv文件读取数据

func ReadCSVTableFrom added in v1.0.10

func ReadCSVTableFrom(rd io.Reader) (*CSVTable, error)

func (*CSVTable) ColSize added in v1.0.10

func (t *CSVTable) ColSize() int

ColSize returns the number of columns

func (*CSVTable) GetRowField added in v1.0.10

func (t *CSVTable) GetRowField(rowIdx int, name string) string

GetRowField returns the field value of the column

func (*CSVTable) RowSize added in v1.0.10

func (t *CSVTable) RowSize() int

RowSize returns the number of rows

func (*CSVTable) ScanRow added in v1.0.10

func (t *CSVTable) ScanRow(row int, target any) error

type Frame added in v1.0.10

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) PC added in v1.0.10

func (f Frame) PC() uintptr

PC returns the program counter for this frame; multiple frames may have the same PC value.

type Pair added in v1.0.10

type Pair[T1, T2 any] struct {
	First  T1
	Second T2
}

Pair is a type that provides a way to store two heterogeneous objects as a single unit.

func MakePair added in v1.0.10

func MakePair[T1, T2 any](a T1, b T2) Pair[T1, T2]

MakePair creates a Pair object, deducing the target type from the types of arguments

type Range added in v1.0.10

type Range struct {
	Min int
	Max int
}

Range contains a min value and a max value

func ParseRange added in v1.0.10

func ParseRange(text, sep string) Range

func (*Range) In added in v1.0.10

func (r *Range) In(val int) bool

In returns true if the value is in the range

func (*Range) Mid added in v1.0.10

func (r *Range) Mid() int

Mid returns the middle value of the range

func (*Range) Rand added in v1.0.10

func (r *Range) Rand() int

Rand returns a random value in the range

type Stack added in v1.0.10

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

Stack represents a stack of program counters.

func GetCallerStack added in v1.0.10

func GetCallerStack(skip int) Stack

GetCallerStack 获取当前调用栈

func (Stack) CallerNames added in v1.0.10

func (s Stack) CallerNames(limit int) []string

CallerNames 获取堆栈函数名

func (Stack) String added in v1.0.10

func (s Stack) String() string

Jump to

Keyboard shortcuts

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