util

package
v0.0.0-...-40138e8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTransMessage = map[string]map[string]string{
	"alphanum": {
		"en": "must be alphanum",
		"zh": "必须是字母或者数字",
	},
	"base64": {
		"en": "must be eq {0}",
		"zh": "必须等于{0}",
	},
	"contains": {
		"en": "must contains {0}",
		"zh": "必须等于{0}",
	},
	"email": {
		"en": "invalid email address",
		"zh": "无效的邮箱地址",
	},
	"gt": {
		"en": "must gt {0}",
		"zh": "必须大于{0}",
	},
	"gte": {
		"en": "must gte {0}",
		"zh": "必须大于等于{0}",
	},
	"ip": {
		"en": "invalid IP address",
		"zh": "无效的IP地址",
	},
	"len": {
		"en": "length must be {0}",
		"zh": "长度必须是{0}位",
	},
	"lt": {
		"en": "must lt {0}",
		"zh": "必须小于{0}",
	},
	"lte": {
		"en": "must lte {0}",
		"zh": "必须小于等于{0}",
	},
	"max": {
		"en": "max is {0}",
		"zh": "最大值是{0}",
	},
	"min": {
		"en": "min is {0}",
		"zh": "最小值是{0}",
	},
	"numeric": {
		"zh": "必须是数字",
		"en": "must numeric",
	},
	"oneof": {
		"en": "only allow in [{0}]",
		"zh": "只能是以下值: [{0}]",
	},
	"required": {
		"zh": "不能为空",
		"en": "can not be empty",
	},
	"url": {
		"en": "invalid url address",
		"zh": "无效的URL地址",
	},
}

Functions

func Crc32

func Crc32(str string) uint32

func GenerateToken

func GenerateToken(id string, authName ...string) (string, error)

generate token pass auth name to use different option

func GenerateTokenPayload

func GenerateTokenPayload(id string, payload interface{}, authName ...string) (string, error)

generate token payload is an extension info pass auth name to use different option

func GetErrors

func GetErrors(err error) map[string]string

func IntVal

func IntVal(str string) int

func Locales

func Locales(l ...locales.Translator)

func M16

func M16(str string) string

16位md5

func Md5

func Md5(str string) string

func SetJwtOption

func SetJwtOption(opt *JwtOption)

func UniqueId

func UniqueId() string

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	Id      string `json:"id"`
	Payload interface{}
}

func ParseToken

func ParseToken(token string, authName ...string) (*Claims, error)

parse token string

type JwtOption

type JwtOption struct {
	SecretKey []byte
	Timeout   int64
	AuthName  string
}

JwtOption

func GetJwtOption

func GetJwtOption(AuthName string) *JwtOption

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator 验证器

func (*Validator) Engine

func (v *Validator) Engine() interface{}

Engine 获取验证器

func (*Validator) ValidateStruct

func (v *Validator) ValidateStruct(obj interface{}) error

ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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