util

package
v0.5.9 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AsciiChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+,.?/:;{}[]`~")

Functions

func BankerRounding added in v0.4.4

func BankerRounding(num interface{}, accuracy int) (f float64)

银行家舍入法 不适用于取整,特别是1,会输出0 具体规则: 1. 被修约的数字小于5时,该数字舍去; 2. 被修约的数字大于5时,则进位; 3. 被修约的数字等于5时,要看5前面的数字,若是奇数则进位,若是偶数则将5舍掉,即修约后末尾数字都成为偶数;若5的后面还有不为“0”的任何数,则此时无论5的前面是奇数还是偶数,均应进位。

func ByteToFloat32 added in v0.5.0

func ByteToFloat32(bytes []byte) float32

BytesToUint16 converts a little endian array of bytes to an array of unit16s

func CheckPwd added in v0.1.19

func CheckPwd(reqPwd, dataPwd string) error

不同数据的加密值一定不同,相同数据的加密值一定相同,因此,在处理用户登录时只需要对用户传递的密码做加密处理,并与原加密值做比较是否一致即可

func Encrypt added in v0.1.19

func Encrypt(password string) (encryptPwd string)

MD5单向加密

func FatalOnError

func FatalOnError(err error, msg string, data ...interface{})

func MapRound added in v0.5.0

func MapRound(m map[string]interface{}, accuracy int)

将map中的float值进行舍入

func NewLen added in v0.1.20

func NewLen(length int) string

func NewLenChars added in v0.1.20

func NewLenChars(length int, chars []byte) string

NewLenChars returns a new random string of the provided length, consisting of the provided byte slice of allowed characters(maximum 256).

func WipeOutZero added in v0.1.20

func WipeOutZero(buf []byte) []byte

去除[]byte中的0 适用于提取ascII码

Types

type Exception added in v0.1.27

type Exception int
var (
	Success Exception = 2000

	//请求类
	RequestTimeOut Exception = 3000
	InvalidParams  Exception = 3001

	//序列化类
	UnmarshalFailed Exception = 6000
	MarshalFailed   Exception = 6001

	//消息处理类
	RedisPublishFailed   Exception = 7000
	RedisSubscribeFailed Exception = 7002
	SetCacheFailed       Exception = 7003
	GetCacheFailed       Exception = 7004

	MQPublishFailed Exception = 7005

	//文件表格操作类
	CreateXLSXFailed Exception = 8000
	InvalidExcel     Exception = 8001
	UploadFileFailed Exception = 8002
	OpenFileFailed   Exception = 8003
	CreateFileFailed Exception = 8004
	WriteFileFailed  Exception = 8005
	ReadFileFailed   Exception = 8006

	//微服务类
	DomainRecordNotExist        Exception = 9000
	GetDomainRecordsFailed      Exception = 9001
	UpdateDomainRecordFailed    Exception = 9002
	CheckDomainRecordFailed     Exception = 9003
	SetDomainRecordStatusFailed Exception = 9004

	EnableThingFailed     Exception = 9010
	DisableThingFailed    Exception = 9011
	CheckDeviceNameFailed Exception = 9012
	RegisterDeviceFailed  Exception = 9013
	GetDeviceSecretFailed Exception = 9014
	SendCaptchaFailed     Exception = 9020

	// influx
	WriteInfluxFailed Exception = 9030
	QueryInfluxFailed Exception = 9031

	// 通用
	UnknownType Exception = 10000
)

func (Exception) Error added in v0.1.27

func (e Exception) Error() error

func (Exception) Name added in v0.2.1

func (e Exception) Name() string

func (Exception) String added in v0.1.27

func (e Exception) String() string

type Message added in v0.3.0

type Message interface {
	Error() error
	Name() string
	String() string
}

Jump to

Keyboard shortcuts

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