cmn

package module
v0.0.0-...-e929c61 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2018 License: MIT Imports: 25 Imported by: 1

README

cmn

golang公共函数库

cmn.P(cmn.Color.Blue("ffff"))
cmn.P(cmn.Rand.RandStr(4))

cmn.Assert.StrEqual(cmn.Str(cmn.Err.GetResultWithoutErr(cmn.Json.Marshal(&Js{
    A: "ddd", C: "dd", D: "dd", M: "dd", I: "fff", Q: Js1{
        A: "ddd", C: "dd", D: "dd", M: "dd", I: "fff",
    },
}))), `{"a":"ddd","c":"dd","d":"dd","q":{"a":"ddd","c":"dd","d":"dd","m":"dd","i":"fff"},"m":"dd","i":"fff"}`)

cmn.Assert.StrEqual(cmn.Str(cmn.Err.GetResultWithoutErr(cmn.Json.MarshalStructWithSorted(&Js{
    A: "ddd", C: "dd", D: "dd", M: "dd", I: "fff", Q: Js1{
        A: "ddd", C: "dd", D: "dd", M: "dd", I: "fff",
    },
}))), `{"a":"ddd","c":"dd","d":"dd","i":"fff","m":"dd","q":{"a":"ddd","c":"dd","d":"dd","i":"fff","m":"dd"}}`)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Assert = myAssert{}
View Source
var Color = color{
	// contains filtered or unexported fields
}
View Source
var Err = myErr{}
View Source
var Hash = myHash{}
View Source
var Json = myJson{}
View Source
var OS = myOS{}
View Source
var Rand = myRand{
	// contains filtered or unexported fields
}
View Source
var Tree = myTree{}

Functions

func B2ds

func B2ds(v []byte) string

B2ds return a Digit string of v v (8-byte big endian) -> uint64(123456) -> "123456".

func B2i

func B2i(v []byte) uint64

Btoi return an int64 of v v (8-byte big endian) -> uint64(123456).

func B2s

func B2s(b []byte) string

B2s converts byte slice to a string without memory allocation. []byte("abc") -> "abc" s

func BConcat

func BConcat(slices ...[]byte) []byte

BConcat concat a list of byte

func BMap

func BMap(m [][]byte, fn func(i int, k []byte) []byte) [][]byte

func Between

func Between(v, min, max []byte) bool

范围判断 min <= v <= max

func ByteToFloat64

func ByteToFloat64(bytes []byte) float64

func ByteToInt

func ByteToInt(x []byte) int

func ByteToInt64

func ByteToInt64(x []byte) int64

func BytesTrimSpace

func BytesTrimSpace(bs []byte) []byte

func CheckClockDrift

func CheckClockDrift() error

func CopyBytes

func CopyBytes(src []byte) []byte

复制数组

func DS2b

func DS2b(v string) []byte

DS2b returns an 8-byte big endian representation of Digit string v ("123456") -> uint64(123456) -> 8-byte big endian.

func DS2i

func DS2i(v string) uint64

DS2i returns uint64 of Digit string v ("123456") -> uint64(123456).

func F

func F(format string, a ...interface{}) string

func Float64ToByte

func Float64ToByte(float float64) []byte

func I2b

func I2b(v uint64) []byte

Itob returns an 8-byte big endian representation of v v uint64(123456) -> 8-byte big endian.

func If

func If(b bool, trueVal, falseVal interface{}) interface{}

func Int64ToByte

func Int64ToByte(x int64) []byte

使用二进制存储整形

func IntToByte

func IntToByte(x int) []byte

使用二进制存储整形

func NewKBuffer

func NewKBuffer() *kBuffer

func P

func P(a ...interface{})

func S2b

func S2b(s string) []byte

S2b converts string to a byte slice without memory allocation. "abc" -> []byte("abc")

func Str

func Str(a interface{}) string

func StrP

func StrP(a interface{})

Types

type BufferCloser

type BufferCloser struct {
	bytes.Buffer
	Closed bool
}

NOTE: Not goroutine safe

func NewBufferCloser

func NewBufferCloser(buf []byte) *BufferCloser

func (*BufferCloser) Close

func (bc *BufferCloser) Close() error

func (*BufferCloser) Write

func (bc *BufferCloser) Write(p []byte) (n int, err error)

func (*BufferCloser) WriteByte

func (bc *BufferCloser) WriteByte(c byte) error

func (*BufferCloser) WriteRune

func (bc *BufferCloser) WriteRune(r rune) (n int, err error)

func (*BufferCloser) WriteString

func (bc *BufferCloser) WriteString(s string) (n int, err error)

type LocalNtpValidator

type LocalNtpValidator struct {
	// Number of measurements to do against the NTP server
	NtpChecks uint64

	// ntpPool is the NTP server to query for the current time
	NtpPool string

	ConnReadTimeout time.Duration

	// Allowed clock drift before warning user
	DriftThreshold time.Duration

	// ntp服务器检测超时次数
	NtpFailureThreshold int
	//在重复NTP警告之前需要经过的最短时间
	NtpWarningCooldown time.Duration
}

func (*LocalNtpValidator) Check

func (v *LocalNtpValidator) Check() error

type PrefixedReader

type PrefixedReader struct {
	Prefix []byte
	// contains filtered or unexported fields
}

func NewPrefixedReader

func NewPrefixedReader(prefix []byte, reader io.Reader) *PrefixedReader

func (*PrefixedReader) Read

func (pr *PrefixedReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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