gext

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: BSD-3-Clause Imports: 23 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

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

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 MarshalProtoJSON

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

func ReadGCPercent() uint64

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

func ReadMemoryLimit

func ReadMemoryLimit() string

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

func ReadMetrics

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

func StartProfiler(addr string)

func TraceStack

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

func UnmarshalProtoJSON

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

Types

type Frame

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

func (f Frame) PC() uintptr

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

type Stack

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

Stack represents a stack of program counters.

func GetCallerStack

func GetCallerStack(skip int) Stack

GetCallerStack 获取当前调用栈

func (Stack) CallerNames

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

CallerNames 获取堆栈函数名

func (Stack) String

func (s Stack) String() string

Jump to

Keyboard shortcuts

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