utils

package
v0.0.0-...-df226ee Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWalkSkipDir = errors.New("skip this directory")

ErrWalkSkipDir is the Error returned when we want to skip descending into a directory

Functions

func Any

func Any(value interface{}) string

func ByteToBase10

func ByteToBase10(b []byte) (n uint64, err error)

func Bytes2String

func Bytes2String(b []byte) (s string)

func DecimalPrecision

func DecimalPrecision(f float64) float64

为float64指定2位小数位

func FileExists

func FileExists(fpath string) (bool, error)

Exists determines whether a file/directory exists or not.

func Float64Bits

func Float64Bits(f float64, d int)

打印浮点数的特定表现格式

func FormatAtom

func FormatAtom(v reflect.Value) string

func GenCqlInString

func GenCqlInString(ss []string) string

func GenSqlInString

func GenSqlInString(ss []string) string

生成 ('a','b','c')的形式

func GetGID

func GetGID() uint64

func GetStack

func GetStack(all bool) string

func HardwareAddr

func HardwareAddr() (string, error)

func HashS2UI32

func HashS2UI32(s string) uint32

HashS2UI32 string转uint32

func HashS2UI64

func HashS2UI64(s string) uint64

HashS2UI64 string转uint64

func Hostname

func Hostname() (string, error)

func Interface2Int

func Interface2Int(v interface{}) int

将interface{}类型转为int类型

func Interface2String

func Interface2String(v interface{}) (string, error)

将interface{}类型转为string类型

func IsCellphone

func IsCellphone(str ...string) bool

手提电话(不带前缀)最高11位

func IsDecimals

func IsDecimals(str ...string) bool

纯小数

func IsEOF

func IsEOF(err error) bool

判断一个error是否是io.EOF

func IsEmail

func IsEmail(s string) (bool, error)

邮箱 最高30位

func IsEngishLowCase

func IsEngishLowCase(str ...string) bool

************************ 英文类型 ************************ 仅小写

func IsEnglish

func IsEnglish(str ...string) bool

大小写混合

func IsEnglishCap

func IsEnglishCap(str ...string) bool

仅大写

func IsID

func IsID(str ...string) bool

************************ 自定义类型 *********************** 数字+字母 不限制大小写 6~30位

func IsIP

func IsIP(s string) bool

IP

func IsInteger

func IsInteger(str ...string) bool

************************ 数字类型 *********************** 纯整数

func IsPwd

func IsPwd(str ...string) bool

数字+字母+符号 6~30位

func IsTelephone

func IsTelephone(str ...string) bool

家用电话(不带前缀) 最高8位

func IsURL

func IsURL(s string) bool

HTTP URL

func LocalIP

func LocalIP() string

获取本机ip

func MSToTime

func MSToTime(ms int64) (time.Time, error)

func MiniteTimestamp

func MiniteTimestamp(offset int64) int64

获取分钟级别的时间戳,可以指定分钟offset

func MurMurHash

func MurMurHash(data []byte) uint32

GetHash returns a murmur32 hash for the data slice.

func NSToTime

func NSToTime(ns int64) (time.Time, error)

func OnlyAlpha

func OnlyAlpha(s string) bool

func OnlyAlphaAndMinus

func OnlyAlphaAndMinus(s string) bool

字符串只允许英文字母和中划线

func OnlyAlphaAndNum

func OnlyAlphaAndNum(s string) bool

检查字符串是否由中文、英文、数字组成

func OnlyAlphaNumAndDot

func OnlyAlphaNumAndDot(s string) bool

func OnlyAlphaNumAndUri

func OnlyAlphaNumAndUri(s string) bool

func PrintStack

func PrintStack(all bool)

打印当前堆栈

func PrivateIPv4

func PrivateIPv4() (net.IP, error)

func RandString

func RandString() string

生成随机字符串

func ReadFull

func ReadFull(conn net.Conn, b []byte, t int) (int, error)

func RuntimeStats

func RuntimeStats(gc bool, heapObj bool, goroutineNum bool) []int64

获取常用runtime统计信息

func SplitString

func SplitString(str string) []string

SplitString splits a string by commas or empty spaces.

func String2Bytes

func String2Bytes(s string) (b []byte)

zero-coy, string类型转为[]byte 注意,这种做法下,一旦string变化,程序立马崩溃且不能recover 谨慎,黑科技!!除非性能瓶颈,否则请使用[]byte(s)

func StringToTime

func StringToTime(s string) (time.Time, error)

将"2016-02-15 12:00:00"或者"2016-04-18 09:33:56.694"等格式转化为time.Time

func StringToTime1

func StringToTime1(s string) (time.Time, error)

将"2016-04-22T21:47:49.694123232+08:00"或者"2016-04-22T21:47:49+08:00"等格式转化为time.Time

func StringToTime2

func StringToTime2(s string) (time.Time, error)

func Time2String

func Time2String(t time.Time) string

func Time2StringMinute

func Time2StringMinute(t time.Time) string

func Time2StringSecond

func Time2StringSecond(t time.Time) string

func Time2Version

func Time2Version(t time.Time) string

func TraceCode

func TraceCode() func()

测量一段代码执行时间

func TransfarIP

func TransfarIP() string

func TrimBytesExtraLineAndSpace

func TrimBytesExtraLineAndSpace(s []byte) []byte

func TrimStringExtraLineAndSpace

func TrimStringExtraLineAndSpace(s string) string

如果是连续的换行,则只保留一个换行 如果是tab,则替换为空格 如果是连续的空格,则只保留一个空格

func UnixMsToTimestring

func UnixMsToTimestring(n int64) string

func UnixMsToTimestringMinute

func UnixMsToTimestringMinute(n int64) string

func UnixToTimestring

func UnixToTimestring(n int64) string

func Walk

func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, walkFn WalkFunc) error

Walk walks a path, optionally following symbolic links, and for each path, it calls the walkFn passed.

It is similar to filepath.Walk, except that it supports symbolic links and can detect infinite loops while following sym links. It solves the issue where your WalkFunc needs a path relative to the symbolic link (resolving links within walkfunc loses the path to the symbolic link for each traversal).

Types

type BufferPool

type BufferPool struct {
	sync.Pool
}

BufferPool represents a thread safe buffer pool

func NewBufferPool

func NewBufferPool(bufferSize int) (bp *BufferPool)

NewBufferPool creates a new BufferPool bounded to the given size.

func (*BufferPool) Get

func (bp *BufferPool) Get() *bytes.Buffer

Get gets a Buffer from the SizedBufferPool, or creates a new one if none are available in the pool. Buffers have a pre-allocated capacity.

func (*BufferPool) Put

func (bp *BufferPool) Put(b *bytes.Buffer)

Put returns the given Buffer to the SizedBufferPool.

type WalkFunc

type WalkFunc func(resolvedPath string, info os.FileInfo, err error) error

WalkFunc is a callback function called for each path as a directory is walked If resolvedPath != "", then we are following symbolic links.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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