utils

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

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

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 12 Imported by: 0

README

golang utility

golang test

go test

go test -v

go test -v hello_test.go

go test -v -test.run TestAgent

go test -cover -coverprofile=cover.out

go tool cover -html=cover.out -o coverage.html

go test -bench=. -run=none -benchmem

go test ./... -cover -coverprofile=cover.out -coverpkg=github.com/hujia-team/annotations_tool,github.com/hujia-team/annotations_tool/modules/dbm

运行当前目录,包括子目录中的所有测试文件
go test ./...
This should run all tests with import path prefixed with `foo/`:
go test foo/...

例子:
go test github.com/hujia-team/annotations_tool/...
运行包 github.com/hujia-team/annotations_tool 下面,包括子目录的所有测试文件
buffer reader
bytes.Buffer()
bytes.NewReader()
bufio.NewReader()
seperator in code
// ---------------------------------------------------

Documentation

Overview

Provides leaky buffer, based on the example in Effective Go.

Index

Constants

View Source
const (
	NanoPerMicro  = 1000
	NanoPerMilli  = 1000 * NanoPerMicro
	NanoPerSecond = 1000 * NanoPerMilli
	NanoPerMinute = 60 * NanoPerSecond
	NanoPerHour   = 60 * NanoPerMinute
	NanoPerDay    = 24 * NanoPerHour
	NanoPerWeek   = 7 * NanoPerDay

	MicroPerMilli  = 1000
	MicroPerSecond = 1000 * MicroPerMilli
	MicroPerMinute = 60 * MicroPerSecond
	MicroPerHour   = 60 * MicroPerMinute
	MicroPerDay    = 24 * MicroPerHour
	MicroPerWeek   = 7 * MicroPerDay

	MilliPerSecond = 1000
	MilliPerMinute = 60 * MilliPerSecond
	MilliPerHour   = 60 * MilliPerMinute
	MilliPerDay    = 24 * MilliPerHour
	MilliPerWeek   = 7 * MilliPerDay

	SecondsPerMinute = 60
	SecondsPerHour   = 60 * SecondsPerMinute
	SecondsPerDay    = 24 * SecondsPerHour
	SecondsPerWeek   = 7 * SecondsPerDay
)

Variables

View Source
var GLeakyBuf = NewLeakyBuf(maxNBuf, leakyBufSize)

Functions

func AfterSeconds

func AfterSeconds(secs int) time.Time

AfterSeconds return secs seconds from now.

func BPutUint16

func BPutUint16(b []byte, v uint16)

func BPutUint32

func BPutUint32(b []byte, v uint32)

func BPutUint64

func BPutUint64(b []byte, v uint64)

func BUint16

func BUint16(b []byte) uint16

func BUint32

func BUint32(b []byte) uint32

func BUint64

func BUint64(b []byte) uint64

func BytesToInt32

func BytesToInt32(b []byte) int

BytesToInt32 change byte array to int.

func CopyMap

func CopyMap(dest, src map[string]interface{})

CopyMap copy src to dest

func CutMsgWithTemplate

func CutMsgWithTemplate(tpl interface{}, msg interface{}) interface{}

CutMsgWithTemplate 根据 tpl 从 msg 中取出数据,放到 result 中

func FileExists

func FileExists(path string) bool

FileExists judge whether file or directory exists.

func GetRandomBytes

func GetRandomBytes(n int, alphabets ...byte) []byte

GetRandomBytes generate random byte slice @param n[in]: the length of random string

func GetRandomString

func GetRandomString(n int, alphabets ...byte) string

GetRandomString generate random string @param n[in]: the length of random string

func Int32Distinct

func Int32Distinct(intList []int32) []int32

Int32Distinct get distinct elements from intList

func Int32ListEqual

func Int32ListEqual(a []int32, b []int32) bool

Int32ListEqual judge list a is equal to list b.

func Int32ListRemove

func Int32ListRemove(intList []int32, element int) []int32

Int32ListRemove remove element in intList

func Int64ToString

func Int64ToString(num int64) string

Int64ToString convert int64 to string

func IntTo4Bytes

func IntTo4Bytes(n int) []byte

IntTo4Bytes change int to 4 bytes.

func IntToString

func IntToString(num int) string

IntToString change int to string.

func IsDir

func IsDir(path string) bool

IsDir check path is directory or not.

func IsFile

func IsFile(path string) bool

IsFile check path is file or not.

func IsStringInArray

func IsStringInArray(str string, array []string) bool

IsStringInArray is str in array

func IsStringWildCardMatchArray

func IsStringWildCardMatchArray(s string, array []string) bool

IsStringWildCardMatchArray 在数组 array 中查找字符串 s,用通配符匹配。

func LPutUint16

func LPutUint16(b []byte, v uint16)

func LPutUint32

func LPutUint32(b []byte, v uint32)

func LPutUint64

func LPutUint64(b []byte, v uint64)

func LUint16

func LUint16(b []byte) uint16

func LUint32

func LUint32(b []byte) uint32

func LUint64

func LUint64(b []byte) uint64

func MakeTimeFromMicroSeconds

func MakeTimeFromMicroSeconds(usec int64) time.Time

MakeTimeFromMicroSeconds construct one time.Time from micro second

func MakeTimeFromMilliSeconds

func MakeTimeFromMilliSeconds(msec int64) time.Time

MakeTimeFromMilliSeconds construct one time.Time from milli second

func MakeTimeFromNanoSeconds

func MakeTimeFromNanoSeconds(nsec int64) time.Time

MakeTimeFromNanoSeconds construct one time.Time from nano second

func MakeTimeFromSeconds

func MakeTimeFromSeconds(sec int64) time.Time

MakeTimeFromSeconds construct one time.Time from second

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func NewRandString

func NewRandString(alphabets string, length int) string

NewRandString generate random string

func ObjectToJSONBuffer

func ObjectToJSONBuffer(obj interface{}) (res []byte)

ObjectToJSONBuffer json marshal

func PackUint32BE

func PackUint32BE(num uint32) []byte

PackUint32BE pack uint32 to []byte, in big endian.

func PackUint32LE

func PackUint32LE(num uint32) []byte

PackUint32LE pack uint32 to []byte, in little endian.

func PathExists

func PathExists(path string) (bool, error)

PathExists judge whether file or directory exists. return:

true, nil : exist.
false, nil: not exist.
false, err: I don't know.

func SelfDir

func SelfDir() string

SelfDir gets compiled executable file directory

func SelfPath

func SelfPath() string

SelfPath gets compiled executable file absolute path

func StringToFloat32

func StringToFloat32(str string) float32

StringToFloat32 convert string to float32

func StringToFloat64

func StringToFloat64(str string) float64

StringToFloat64 convert string to float64

func StringToInt

func StringToInt(str string) int

StringToInt change string to int.

func StringToInt64

func StringToInt64(str string) int64

StringToInt64 convert string to int64

func StringToUint32

func StringToUint32(str string) uint32

StringToUint32 convert string to uint32

func StringToUint64

func StringToUint64(str string) uint64

StringToUint64 convert string to uint64

func TimeNowMicroSecond

func TimeNowMicroSecond() int64

TimeNowMicroSecond now microsecond.

func TimeNowMilliSecond

func TimeNowMilliSecond() int64

TimeNowMilliSecond now millisecond.

func TimeNowNonoSecond

func TimeNowNonoSecond() int64

TimeNowNonoSecond now nanosecond.

func TimeNowSecond

func TimeNowSecond() int64

TimeNowSecond now second.

func ToInt

func ToInt(value interface{}) (num int, err error)

ToInt change interface to number.

func ToInt64

func ToInt64(value interface{}) (num int64, err error)

ToInt64 change interface to int64.

func Uint64ToString

func Uint64ToString(num uint64) string

Uint64ToString convert uint64 to string

func UnpackUint32BE

func UnpackUint32BE(data []byte) uint32

UnpackUint32BE unpack []byte to uint32, in big endian.

func UnpackUint32LE

func UnpackUint32LE(data []byte) uint32

UnpackUint32LE unpack []byte to uint32, in little endian.

func WildCardDeepMatchRune

func WildCardDeepMatchRune(pattern, name []rune, plus bool) bool

func WildCardMatch

func WildCardMatch(pattern string, name string) bool

WildCardMatch 通配符匹配字符串 ?: 匹配 0 个或者 1 个字符 *: 匹配 0 个,1 个或者任意多个字符 +: 匹配 1 个字符或者任意个字符,也就是至少 1 个字符

WildCardMatch("a?c", "abc") == true WildCardMatch("a?c", "ac") == true

WildCardMatch("a*c", "ac") == true WildCardMatch("a*c", "abc") == true WildCardMatch("a*c", "abbbc") == true

WildCardMatch("a+c", "ac") == false WildCardMatch("a+c", "abc") == true WildCardMatch("a+c", "abbbc") == true

Types

type LeakyBuf

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

func NewLeakyBuf

func NewLeakyBuf(n, bufSize int) *LeakyBuf

NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each with bufSize bytes.

func (*LeakyBuf) Get

func (lb *LeakyBuf) Get() (b []byte)

Get returns a buffer from the leaky buffer or create a new buffer.

func (*LeakyBuf) Put

func (lb *LeakyBuf) Put(b []byte)

Put add the buffer into the free buffer pool for reuse. Panic if the buffer size is not the same with the leaky buffer's. This is intended to expose error usage of leaky buffer.

Directories

Path Synopsis
Package cache provide a Cache interface and some implement engine Usage: import( "github.com/astaxie/beego/cache" ) bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: bm.Put("astaxie", 1, 10 * time.Second) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
Package cache provide a Cache interface and some implement engine Usage: import( "github.com/astaxie/beego/cache" ) bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: bm.Put("astaxie", 1, 10 * time.Second) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") more docs http://beego.me/docs/module/cache.md
commander
du
container
ini
log
Package log implements a simple logging package.
Package log implements a simple logging package.
logrus
x

Jump to

Keyboard shortcuts

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