util

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 23 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 (
	Space          = " "  // ASCII 32
	Tab            = "\t" // ASCII 9
	Newline        = "\n" // ASCII 10
	CarriageReturn = "\r" // ASCII 13
	VerticalTab    = "\v" // ASCII 11
	FormFeed       = "\f" // ASCII 12
)

space run as string, space character as string

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 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

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 ConRun added in v1.1.0

func ConRun(fns ...Fn)

func DeepCopyByJSON added in v1.1.9

func DeepCopyByJSON(stdJSON StdJSON, v any) any

DeepCopyByJSON no tested yet

func DefaultHTTPClient added in v1.1.0

func DefaultHTTPClient() *http.Client

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 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 MapOk added in v1.1.4

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

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 Must added in v1.1.7

func Must(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 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 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 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 String2BytesNoCopy

func String2BytesNoCopy(s string) []byte

func StringConcat

func StringConcat(s ...string) string

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 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 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

Types

type Byteser added in v1.1.4

type Byteser interface {
	Bytes() []byte
}

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 {
	Unmarshal(b []byte, v any)
}

type JSONEncoder added in v1.1.0

type JSONEncoder interface {
	Marshal(v any) []byte
}

type JSONer added in v1.1.9

type JSONer interface {
	JSONEncoder
	JSONDecoder
}

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 StdJSON added in v1.1.9

type StdJSON interface {
	StdJSONEncoder
	StdJSONDecoder
}

type StdJSONDecoder added in v1.1.9

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

type StdJSONEncoder added in v1.1.0

type StdJSONEncoder interface {
	Marshal(v any) ([]byte, error)
}

type Stringer added in v1.1.4

type Stringer fmt.Stringer

Directories

Path Synopsis
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