util

package
v0.0.0-...-65a89f1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(s string) ([]byte, error)

Base64Decode .

func Base64Encode

func Base64Encode(data []byte) string

Base64Encode .

func CheckStringSize

func CheckStringSize(body string, sizeLimit int64) error

func ErrorContains

func ErrorContains(err error, substr string) bool

ErrorContains returns NoCaseContains(err.Error(), substr) Returns false if err is nil.

func Panic

func Panic(err error)

Panic panics if err != nil

func PathIsExist

func PathIsExist(name string) bool

PathIsExist .

func PathIsNotExist

func PathIsNotExist(name string) (ok bool)

func RandomID

func RandomID() string

RandomID 返回一个上升趋势的随机 id, 由时间戳与随机数组成。 时间戳确保其上升趋势(大致有序),随机数确保其随机性(防止被穷举, 防冲突)。 RandomID 考虑了 “生成 id 的速度”、 “并发防冲突” 与 “id 长度” 这三者的平衡,适用于大多数中、小规模系统(当然,不适用于大型系统)。

func RemoveIfExist

func RemoveIfExist(name string) (err error)

func StringLimit

func StringLimit(s string, limit int) string

StringLimit 截取 s, 确保 s 不大于 limit. 同时会确保截取后的 s 是有效的 utf8 字符串.

func TimeNow

func TimeNow() int64

func WrapErrors

func WrapErrors(allErrors ...error) (wrapped error)

WrapErrors 把多个错误合并为一个错误.

Types

This section is empty.

Jump to

Keyboard shortcuts

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