utils

package
v0.0.0-...-38a39c4 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: MIT Imports: 18 Imported by: 0

README

util

业务工具包

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString 字节切片转字符串

func ConcatString

func ConcatString(s ...string) string

ConcatString 连接字符串 NOTE: 性能比fmt.Sprintf和+号要好

func Extract

func Extract(hostPort string, lis net.Listener) (string, error)

Extract returns a private addr and port.

func ExtractHostPort

func ExtractHostPort(addr string) (host string, port uint64, err error)

ExtractHostPort from address

func GenShortID

func GenShortID() (string, error)

GenShortID 生成一个id

func GetBytes

func GetBytes(key interface{}) ([]byte, error)

GetBytes interface 转 byte

func GetDate

func GetDate() string

GetDate 获取字符串日期

func GetHostname

func GetHostname() string

GetHostname 获取主机名

func GetInternalIP

func GetInternalIP() string

GetInternalIP get internal ip.

func GetLocalIP

func GetLocalIP() string

GetLocalIP 获取本地内网IP

func GetShowTime

func GetShowTime(ts time.Time) string

GetShowTime 格式化时间

func GetTodayDateInt

func GetTodayDateInt() int

GetTodayDateInt 获取整形的日期

func IsEmpty

func IsEmpty(s string) bool

IsEmpty 是否是空字符串

func IsInSlice

func IsInSlice(value interface{}, sli interface{}) bool

IsInSlice 判断某一值是否在slice中 因为使用了反射,所以时间开销比较大,使用中根据实际情况进行选择

func IsZero

func IsZero(i ...interface{}) bool

IsZero 检查是否是零值

func JoinInt

func JoinInt(is []int64) string

JoinInt format int64 slice to string, eg: n1,n2,n3.

func Md5

func Md5(str string) (string, error)

Md5 字符串转md5

func Port

func Port(lis net.Listener) (int, bool)

Port return a real port.

func RandomStr

func RandomStr(n int) string

RandomStr 随机字符串

func RegexpReplace

func RegexpReplace(reg, src, temp string) string

RegexpReplace ...

func Sign

func Sign(payload map[string]interface{}, secret string, timeout int64) (tokenString string, err error)

Sign signs the payload with the specified secret. The token content. iss: (Issuer)签发者 iat: (Issued At)签发时间,用Unix时间戳表示 exp: (Expiration Time)过期时间,用Unix时间戳表示 aud: (Audience)接收该JWT的一方 sub: (Subject)该JWT的主题 nbf: (Not Before)不要早于这个时间 jti: (JWT ID)用于标识JWT的唯一ID

func SliceShuffle

func SliceShuffle(slice []interface{})

SliceShuffle shuffle a slice

func SplitInt

func SplitInt(s string) ([]int64, error)

SplitInt split string into int64 slice.

func StringSliceContains

func StringSliceContains(ss []string, s string) bool

StringSliceContains 字符串切片中是否包含另一个字符串 来自go源码 net/http/server.go

func StringSliceEqual

func StringSliceEqual(a, b []string) bool

StringSliceEqual 判断 string和slice 是否相等 使用了传统的遍历方式

func StringSliceReflectEqual

func StringSliceReflectEqual(a, b []string) bool

StringSliceReflectEqual 判断 string和slice 是否相等 因为使用了反射,所以效率较低,可以看benchmark结果

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes convert string to byte

func StringToInt

func StringToInt(str string) (int, error)

StringToInt 字符串转int

func StringToInt64

func StringToInt64(str string) (int64, error)

StringToInt64 字符串转int64

func StringToUint64

func StringToUint64(str string) (uint64, error)

StringToUint64 字符串转uint64

func TimeLayout

func TimeLayout() string

TimeLayout 常用日期格式化模板

func TimeToShortString

func TimeToShortString(ts time.Time) string

TimeToShortString 时间转日期

func TimeToString

func TimeToString(ts time.Time) string

TimeToString 时间转字符串

func Uint64DeleteElemInSlice

func Uint64DeleteElemInSlice(i int, s []uint64) []uint64

Uint64DeleteElemInSlice 从slice删除元素 fast version, 会改变顺序 i:slice的索引值 s: slice

func Uint64DeleteElemInSliceWithOrder

func Uint64DeleteElemInSliceWithOrder(i int, s []uint64) []uint64

Uint64DeleteElemInSliceWithOrder 从slice删除元素 slow version, 保持原有顺序 i:slice的索引值 s: slice

func Uint64ShuffleSlice

func Uint64ShuffleSlice(a []uint64) []uint64

Uint64ShuffleSlice 对slice进行随机

func Uint64SliceReverse

func Uint64SliceReverse(a []uint64) []uint64

Uint64SliceReverse 对uint64 slice 反转

Types

This section is empty.

Jump to

Keyboard shortcuts

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