gutils

package module
v0.0.0-...-82b3520 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

README

go-utils

go常用工具类

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToString

func ConvertToString(src, srcCode, tagCode string) string

ConvertToString 转换字符串编码 src 字符串 srccode 源编码 tagCode 目标编码

func CreateToken

func CreateToken(subject string, expire time.Duration, secret []byte) (string, error)

CreateToken 生成jwtToken

func DecrptogAES

func DecrptogAES(src, key string) string

DecrptogAES AES解密

func EncyptogAES

func EncyptogAES(src, key string) string

EncyptogAES AES加密

func GenerateRSAKey

func GenerateRSAKey(bits int) (pubKey, priKey []byte, err error)

GenerateRSAKey 生成RSA私钥和公钥,保存到文件中

func IdsUniqueFitter

func IdsUniqueFitter(ids []int) []int

IdsUniqueFitter ids去重

func MD5

func MD5(value string) string

MD5 md5 encryption

func MsgTplCompile

func MsgTplCompile(tpl string, args []string) string

MsgTplCompile 字符串模板渲染 "您的验证码{0},过期时间{1}分钟", ["123", "5"] => 您的验证码123,过期时间5分钟

func MustUtf8

func MustUtf8(s string) string

MustUtf8 强制字符串必须为utf8

func NewLockTable

func NewLockTable() *lockTable

NewLockTable 新建

func PanicToError

func PanicToError(f func()) (err error)

PanicToError Panic转换为error

func PanicTrace

func PanicTrace(err interface{}) string

PanicTrace panic调用链跟踪

func ParseArrString

func ParseArrString(str, sep string, dto interface{}) error

ParseArrString 解析字符串数组 str 待解析字符串 sep 分割符号 dto 期望解析切片(指针)

func ParseToken

func ParseToken(tokenString string, secret []byte) (string, error)

ParseToken 解析jwtToken

func PasswordHash

func PasswordHash(pwd string) string

PasswordHash 密码生成

func PasswordVerify

func PasswordVerify(hashedPwd string, plainPwd string) bool

PasswordVerify 密码验证

func RSADecrypt

func RSADecrypt(cipherText []byte, key []byte) ([]byte, error)

RSADecrypt RSA解密

func RSAEncrypt

func RSAEncrypt(plainText []byte, key []byte) ([]byte, error)

RSAEncrypt RSA加密

func SuperConvert

func SuperConvert(fromStruct interface{}, toStruct interface{})

SuperConvert 使用反射,转换结构体 仅支持单层级

func Validator

func Validator(err error) string

Validator 参数校验错误信息优化

Types

type SafeStringMap

type SafeStringMap struct {
	sync.RWMutex
	Map map[string]string
}

SafeStringMap 安全map

func NewSafeStringMap

func NewSafeStringMap() *SafeStringMap

NewSafeStringMap 创建

func (*SafeStringMap) DEL

func (st *SafeStringMap) DEL(key string)

DEL 删除

func (*SafeStringMap) GET

func (st *SafeStringMap) GET(key string) string

GET 获取

func (*SafeStringMap) SET

func (st *SafeStringMap) SET(key string, value string)

SET 设置

func (*SafeStringMap) SETNX

func (st *SafeStringMap) SETNX(key string, value string) (ok bool)

SETNX map锁

Jump to

Keyboard shortcuts

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