util

package
v1.2.18 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ki = 1 << 10
	Mi = 1 << 20
	Gi = 1 << 30
	Ti = 1 << 40
	Pi = 1 << 50
	Ei = 1 << 60
)

<binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei refer from: resource/quantity.go

View Source
const (
	JSONMarshalPrefix = ""
	JSONMarshalIndent = "  "
)
View Source
const (
	DirMaxPerm  = 0755
	FileMaxPerm = 0644
)
View Source
const (
	Tab     = "\t" // ASCII 9
	Newline = "\n" // ASCII 10
)

space run as string, space character as string

View Source
const (
	// From Null, following is ASCII 0 ~ 127
	Null = `\0` // ASCII 0

	Bell           = `\a` // ASCII 7
	Backspace      = `\b` // ASCII 8
	HorizontalTab  = `\t` // ASCII 9
	LineFeed       = `\n` // ASCII 10
	VerticalTab    = `\v` // ASCII 11
	FormFeed       = `\f` // ASCII 12
	CarriageReturn = `\r` // ASCII 13

	Escape = `\e` // ASCII 27

	Space            = ` ` // ASCII 32
	ExclamationMark  = `!` // ASCII 33
	DoubleQuotes     = `"` // ASCII 34
	SpeechMarks      = `"` // ASCII 34
	NumberSign       = `#` // ASCII 35
	Dollar           = `$` // ASCII 36
	PercentSign      = `%` // ASCII 37
	Ampersand        = `&` // ASCII 38
	SingleQuote      = `'` // ASCII 39
	OpenParenthesis  = `(` // ASCII 40
	OpenBracket      = `(` // ASCII 40
	CloseParenthesis = `)` // ASCII 41
	CloseBracket     = `)` // ASCII 41
	Asterisk         = `*` // ASCII 42
	Plus             = `+` // ASCII 43
	Comma            = `,` // ASCII 44
	HyphenMinus      = `-` // ASCII 45
	Period           = `.` // ASCII 46
	Dot              = `.` // ASCII 46
	FullStop         = `.` // ASCII 46
	Slash            = `/` // ASCII 47
	Divide           = `/` // ASCII 47

	Colon              = `:` // ASCII 58
	Semicolon          = `;` // ASCII 59
	LessThan           = `<` // ASCII 60
	OpenAngledBracket  = `<` // ASCII 60
	Equals             = `=` // ASCII 61
	GreaterThan        = `>` // ASCII 62
	CloseAngledBracket = `>` // ASCII 62
	QuestionMark       = `?` // ASCII 63
	AtSign             = `@` // ASCII 64

	OpeningBracket = `[` // ASCII 91
	Backslash      = `\` // ASCII 92
	ClosingBracket = `]` // ASCII 93
	Caret          = `^` // ASCII 94
	Circumflex     = `^` // ASCII 94
	Underscore     = `_` // ASCII 95
	GraveAccent    = "`" // ASCII 96

	OpeningBrace    = `{`   // ASCII 123
	VerticalBar     = `|`   // ASCII 124
	ClosingBrace    = `}`   // ASCII 125
	EquivalencySign = `~`   // ASCII 126
	Tilde           = `~`   // ASCII 126
	Delete          = `DEL` // ASCII 127
)

Printable and Showable ASCII Table referred from: https://en.wikipedia.org/wiki/ASCII https://www.ascii-code.com/

View Source
const (
	DurationMinute      = time.Second * 60
	DurationHour        = DurationMinute * 60
	DurationHalfDay     = DurationHour * 12
	DurationDay         = DurationHalfDay * 2
	DurationWeek        = DurationDay * 7
	DurationMonth       = DurationDay * 30
	DurationYear        = DurationDay * 365
	DurationEra         = DurationYear * 10
	DurationHalfCentury = DurationEra * 5
	DurationCentury     = DurationHalfCentury * 2
)

for human read

View Source
const (
	MagicBufferCap = 16 * Ki
)
View Source
const (
	MagicMapCap = (iota + 1) << 4
)
View Source
const (
	MagicSliceCap = (iota + 1) << 3
)
View Source
const (
	MagicStr = "Ciallo~"
)
View Source
const (
	TimeLocationAsiaShanghai = "Asia/Shanghai"
)

Variables

This section is empty.

Functions

func Any2a added in v1.1.9

func Any2a(v any) string

func AssertFloat added in v1.2.16

func AssertFloat(v any) bool

func AssertInt added in v1.2.16

func AssertInt(v any) bool

func AssertNumeric added in v1.2.16

func AssertNumeric(v any) bool

func AssertString added in v1.2.16

func AssertString(v any) bool

func AssertStringLike added in v1.2.16

func AssertStringLike(v any) bool

func AssertUint added in v1.2.16

func AssertUint(v any) bool

func AssertZero added in v1.2.16

func AssertZero(v any) bool

func AtoF32 added in v1.1.4

func AtoF32(s string) float32

func AtoF64 added in v1.1.4

func AtoF64(s string) float64

func AtoI64 added in v1.1.1

func AtoI64(s string) int64

func AtoU64 added in v1.1.1

func AtoU64(s string) uint64

func BackgroundContext added in v1.1.0

func BackgroundContext() context.Context

func Bytes2StringNoCopy

func Bytes2StringNoCopy(bs []byte) string

Bytes2StringNoCopy unsafe, long string panic tested

func BytesGB added in v1.1.4

func BytesGB(bs []byte) float64

func BytesKB added in v1.1.4

func BytesKB(bs []byte) float64

func BytesMB added in v1.1.4

func BytesMB(bs []byte) float64

func BytesOf added in v1.1.4

func BytesOf(bs []byte) string

BytesOf get a proper measurement: B/KiB/MiB/GiB/TiB/PiB/EiB

func CST2Timestamp added in v1.1.0

func CST2Timestamp(cst string) string

CST2Timestamp Convert (CST: UTC+8) to (Unix timestamp)

func Camel2Snake added in v1.2.7

func Camel2Snake(camelCase string) string

Camel2Snake +example: snake -> snake +example: snakeToCamel -> snake_to_camel

func CapitalizeFirst added in v1.2.7

func CapitalizeFirst(str string) string

func Colorf added in v1.2.18

func Colorf(val ...ColorValue)

func ConRun added in v1.1.0

func ConRun(fns ...Fn)

func DeepCopyByJSON added in v1.1.9

func DeepCopyByJSON(stdJSON JSONLite, v any) any

DeepCopyByJSON tested is ok

func DefaultHTTPClient added in v1.1.0

func DefaultHTTPClient() *http.Client

func DoWithBuffer added in v1.2.4

func DoWithBuffer(fn WithBufferFn)

func ElemIn added in v1.1.8

func ElemIn[E comparable](e E, s ...E) bool

func ElemsIn added in v1.1.8

func ElemsIn[E comparable](src, dst []E) bool

ElemsIn src all in dst return true ,or not return false

func F32toa added in v1.1.4

func F32toa(f32 float32) string

func F64toa added in v1.1.4

func F64toa(f64 float64) string

func GetBuffer added in v1.1.7

func GetBuffer() *valyalabuffer.ByteBuffer

GetBuffer when GetBuffer from ByteBuffer, must call PutBuffer after GetBuffer

func GetIPv4Str added in v1.1.8

func GetIPv4Str(addr net.Addr) string

func GetIPv6Str added in v1.1.8

func GetIPv6Str(addr net.Addr) string

func GetTypeByteSize added in v1.1.0

func GetTypeByteSize(varOf any) uintptr

func GetValueByteSize added in v1.1.0

func GetValueByteSize(varOf any) int

func GetWorkPath added in v1.2.15

func GetWorkPath(s ...string) string

func GoSafe added in v1.2.0

func GoSafe(fn Fn)

func GreenAny added in v1.1.9

func GreenAny(v any) string

func GreenF added in v1.1.9

func GreenF(format string, v ...any) string

func GzipIOReader2File added in v1.1.4

func GzipIOReader2File(ioReader io.Reader, fileName string) (err error)

func I64toa added in v1.1.0

func I64toa(i64 int64) string

func IOGetStr added in v1.1.3

func IOGetStr(readCloser io.ReadCloser) string

func IPFromAddr added in v1.1.7

func IPFromAddr(addr net.Addr) net.IP

func IPStringFromAddr added in v1.1.7

func IPStringFromAddr(addr []net.Addr) []string

func IsIPv added in v1.1.8

func IsIPv(ip string) uint8

func IsIPv4 added in v1.1.7

func IsIPv4(addr net.Addr) bool

func IsIPv6 added in v1.1.7

func IsIPv6(addr net.Addr) bool

func IsSpace added in v1.1.4

func IsSpace(s string) bool

func IsURLWithHTTP added in v1.1.0

func IsURLWithHTTP(url string) bool

func IsURLWithHTTPS added in v1.1.0

func IsURLWithHTTPS(url string) bool

func IsURLWithScheme added in v1.1.0

func IsURLWithScheme(url string) bool

func LookupIP added in v1.1.7

func LookupIP(host string) string

LookupIP

+example 192.168.31.254 -> 192.168.31.254 +example app.local -> 192.168.31.254 +example 192.168.31.254:80 -> 192.168.31.254:80 +example app.local:80 -> 192.168.31.254:80

func MapClear added in v1.2.9

func MapClear[Map ~map[K]V, K comparable, V any](m ...Map)

func MapCopy added in v1.2.9

func MapCopy[Map ~map[K]V, K comparable, V any](dst, src Map) Map

func MapDelete added in v1.2.9

func MapDelete[Map ~map[K]V, K comparable, V any](m Map, k ...K)

func MapElem added in v1.2.9

func MapElem[Map ~map[K]V, K comparable, V any](m Map, k K) V

MapElem get elem by k from m, never failure if m == nil

func MapElemOk added in v1.2.9

func MapElemOk[Map ~map[K]V, K comparable, V any](m Map, k K) (V, bool)

MapElemOk mapaccess2

func MapEvict added in v1.2.1

func MapEvict[Map1 ~map[K]V1, Map2 ~map[K]V2, K comparable, V1 any, V2 any](dst Map1, src Map2)

MapEvict evict different elem_type map with same key_type map with same key

func MapInsert added in v1.2.9

func MapInsert[Map ~map[E]struct{}, E comparable](m Map, e ...E) Map

func MapKeyMap added in v1.2.14

func MapKeyMap[Map ~map[K]V, KeyMap ~map[K]struct{}, K comparable, V any](m Map) KeyMap

func MapKeys added in v1.2.9

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

func MapMerge added in v1.2.1

func MapMerge[Map ~map[F]M, F comparable, M map[K]V, K comparable, V any](dst, src Map)

MapMerge merge field in src `M`as elem copy to field in dst `M`as elem

func MapOk added in v1.1.4

func MapOk[Map ~map[K]V, K comparable, V any](m Map, k K) bool

MapOk check if k in m, never failure if m == nil

func MapValueMap added in v1.2.14

func MapValueMap[Map ~map[K]V, ValueMap ~map[V]struct{}, K, V comparable](m Map) ValueMap

func MapValues added in v1.2.9

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

func MapsMerge added in v1.2.15

func MapsMerge[Map ~map[K]V, K comparable, V any](m ...Map) Map

func MarshalJSONPretty added in v1.1.0

func MarshalJSONPretty(v any) (string, error)

func MeasureByte added in v1.1.7

func MeasureByte(size int) string

func MeasureTime added in v1.1.7

func MeasureTime(dur time.Duration) string

func MergeError added in v1.2.4

func MergeError(err ...error) error

func Must added in v1.1.7

func Must(err error)

func MustDetail added in v1.2.18

func MustDetail(err error)

func New

func New[T any](val T) *T

func New2 added in v1.1.9

func New2[T any](val T) **T

func NewBool

func NewBool(bVar bool) *bool

func NewFloat32

func NewFloat32(f32 float32) *float32

func NewFloat64

func NewFloat64(f64 float64) *float64

func NewInt32

func NewInt32(i32 int32) *int32

func NewInt64

func NewInt64(i64 int64) *int64

func NewNoZeroInt added in v1.2.18

func NewNoZeroInt[T Number](num T) *T

func NewNoZeroString added in v1.2.18

func NewNoZeroString[T String](s T) *T

func NewString

func NewString(str string) *string

func NewZero added in v1.1.9

func NewZero[T any](val T) *T

func NilStruct added in v1.1.4

func NilStruct() struct{}

func OSCreateAbsoluteDir added in v1.1.0

func OSCreateAbsoluteDir(dir string) error

func OSCreateAbsolutePath added in v1.1.0

func OSCreateAbsolutePath(filePath string) error

OSCreateAbsolutePath unix /opt/xxx windows A:\ A:\\ B:\ B:\\ C:\ C:\\ D:\ D:\\

func OSFilePathExists added in v1.1.0

func OSFilePathExists(filePath string) bool

func OSOpenFileWithCreate added in v1.1.0

func OSOpenFileWithCreate(filePath string) (*os.File, error)

func OSRemoveFile added in v1.1.0

func OSRemoveFile(filePath string) error

func PanicHandler added in v1.2.17

func PanicHandler(v ...any)

func Ptr2a added in v1.1.7

func Ptr2a(v any) string

func PutBuffer added in v1.1.7

func PutBuffer(bb *valyalabuffer.ByteBuffer)

PutBuffer return memory to BufferPool

func ReadYaml added in v1.1.0

func ReadYaml(a any, filePath string) error

ReadYaml Deprecated gopkg.in/aml.v3 can not reflect twice

func Recover added in v1.2.0

func Recover(fn Fn)

Recover any func panic anyway, never hangout

func RedAny added in v1.1.9

func RedAny(v any) string

func RedF added in v1.1.9

func RedF(format string, v ...any) string

func SeqRun added in v1.1.0

func SeqRun(fns ...Fn)

func SilentCloseIO added in v1.1.7

func SilentCloseIO(msg string, closer io.Closer)

SilentCloseIO handle io closer error

func SilentError added in v1.1.7

func SilentError(err error)

SilentError only used in dev env or test env, _test file not to use in production env

func SilentErrorf added in v1.1.7

func SilentErrorf(detail string, err error)

SilentErrorf only used in dev env or test env, _test file not to use in production env

func SilentFatal added in v1.1.7

func SilentFatal(err error)

SilentFatal only used in dev env or test env, _test file not to use in production env

func SilentFatalf added in v1.1.7

func SilentFatalf(detail string, err error)

SilentFatalf only used in dev env or test env, _test file not to use in production env

func SilentPanic added in v1.1.7

func SilentPanic(err error)

SilentPanic only used in dev env or test env, _test file not to use in production env

func Slice2Map added in v1.2.9

func Slice2Map[Slice ~[]E, Map ~map[E]struct{}, E comparable](s Slice) Map

func Snake2Camel added in v1.2.7

func Snake2Camel(snakeCase string) string

Snake2Camel +example: snake -> snake +example: snake_to_camel -> snakeToCamel

func String2BytesNoCopy

func String2BytesNoCopy(s string) []byte

String2BytesNoCopy unsafe, long string panic tested

func String2RuneSlice added in v1.2.15

func String2RuneSlice(s string) []rune

func StringConcat

func StringConcat(s ...string) string

func StringContainAny added in v1.2.15

func StringContainAny(s string, e ...string) bool

func StringContainsAll added in v1.2.15

func StringContainsAll(s string, e ...string) bool

func StringDelete added in v1.1.9

func StringDelete(s string, from ...string) string

func StringJoin added in v1.1.0

func StringJoin(sep string, s ...string) string

func StringPrefixIn added in v1.1.8

func StringPrefixIn(s string, p ...string) bool

func StringQuote added in v1.1.8

func StringQuote(s string) string

func StringReplaceAlls added in v1.1.0

func StringReplaceAlls(s, to string, from ...string) string

func StringSQuote added in v1.1.8

func StringSQuote(s string) string

func StringSlice2RuneSlice added in v1.2.15

func StringSlice2RuneSlice(s []string) []rune

a bit of wrong for type:rune or type:byte?

func TODOContext added in v1.1.0

func TODOContext() context.Context

func TarIOReader2File added in v1.1.4

func TarIOReader2File(ioReader io.Reader, filePath string) (err error)

func TestLongHorizontalLine added in v1.1.9

func TestLongHorizontalLine(t *testing.T)

func TimeSecond added in v1.1.7

func TimeSecond(sec int) time.Duration

func Timestamp2CST added in v1.1.0

func Timestamp2CST(timestamp string) string

Timestamp2CST Convert (Unix timestamp) to (CST: UTC+8)

func ToElemPtrMap added in v1.2.10

func ToElemPtrMap[ElemMap map[K]E, ElemPtrMap map[K]*E, K comparable, E any](m ElemMap) ElemPtrMap

func ToElemPtrSlice added in v1.2.10

func ToElemPtrSlice[ElemSlice []E, ElemPtrSlice []*E, E any](s ElemSlice) ElemPtrSlice

func TrimNetMask added in v1.1.7

func TrimNetMask(ip string) string

func U64toa added in v1.1.1

func U64toa(u64 uint64) string

func URLWithHTTP

func URLWithHTTP(url string) string

func URLWithoutHTTP added in v1.1.0

func URLWithoutHTTP(url string) string

func YN added in v1.1.9

func YN(v bool) string

YN return Y true or N false

func Zero added in v1.2.15

func Zero[V any]() V

Types

type Byteser added in v1.1.4

type Byteser interface {
	Bytes() []byte
}

type ColorValue added in v1.2.18

type ColorValue struct {
	Color color.Attribute
	Value any
}

type Fn added in v1.1.0

type Fn func()

func DoNothing added in v1.1.0

func DoNothing() Fn

func NothingFn added in v1.1.0

func NothingFn() Fn

type Func

type Func func() error

func NothingFunc added in v1.1.4

func NothingFunc() Func

type JSONDecoder added in v1.1.9

type JSONDecoder interface {
	Decode(v any) error
	More() bool
	Buffered() io.Reader
	UseNumber()
	DisallowUnknownFields()
}

type JSONEncoder added in v1.1.0

type JSONEncoder interface {
	Encode(v any) error
	SetIndent(prefix, indent string)
	SetEscapeHTML(on bool)
}

type JSONLite added in v1.2.15

type JSONLite interface {
	JSONMarshaler
	JSONUnmarshaler
}

type JSONMarshaler added in v1.2.15

type JSONMarshaler interface {
	Marshal(v any) ([]byte, error)
	MarshalIndent(v any, prefix, indent string) ([]byte, error)
}

type JSONUnmarshaler added in v1.2.15

type JSONUnmarshaler interface {
	Unmarshal(data []byte, v any) error
}

type JSONer added in v1.1.9

type Number added in v1.2.18

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

type Page

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

func DefaultPage

func DefaultPage() *Page

DefaultPage immutable default page config

func NewPageConfig

func NewPageConfig(pageNum, pageSize int64) *Page

func (*Page) Page

func (p *Page) Page() *int64

func (*Page) PageIntValue added in v1.1.0

func (p *Page) PageIntValue() int

func (*Page) PageValue added in v1.1.0

func (p *Page) PageValue() int64

func (*Page) Pair

func (p *Page) Pair() (*int64, *int64)

func (*Page) PairValue added in v1.1.0

func (p *Page) PairValue() (int64, int64)

func (*Page) Size

func (p *Page) Size() *int64

func (*Page) SizeIntValue added in v1.1.0

func (p *Page) SizeIntValue() int

func (*Page) SizeValue added in v1.1.0

func (p *Page) SizeValue() int64

func (*Page) WithOffsetNum

func (p *Page) WithOffsetNum(offsetNum int64) *Page

func (*Page) WithPageNum

func (p *Page) WithPageNum(pageNum int64) *Page

func (*Page) WithPageSize

func (p *Page) WithPageSize(pageSize int64) *Page

type Sizer added in v1.1.4

type Sizer interface {
	Size() int64
}

type String added in v1.2.18

type String interface {
	~string | ~[]byte
}

type Stringer added in v1.1.4

type Stringer fmt.Stringer

type WithBufferFn added in v1.2.4

type WithBufferFn func(buf *valyalabuffer.ByteBuffer)

Directories

Path Synopsis
mock/v2
Package mockv2 was generated
Package mockv2 was generated
Package safe_cast codegen by codegen/safe_cast_codegen.go, do not edit.
Package safe_cast codegen by codegen/safe_cast_codegen.go, do not edit.

Jump to

Keyboard shortcuts

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