Documentation ¶
Index ¶
- Variables
- func AESDecrypt(key []byte, cryptoText string) (string, bool)
- func AESEncrypt(key []byte, text string) (string, bool)
- func Alpha(validValue interface{}, params ...string) bool
- func AlphaDash(validValue interface{}, params ...string) bool
- func AlphaNumeric(validValue interface{}, params ...string) bool
- func ChnAlphaNumeric(validValue interface{}, params ...string) bool
- func ChnDash(validValue interface{}, params ...string) bool
- func Deserialize(data []byte, to interface{}) error
- func Email(validValue interface{}, params ...string) bool
- func FileExist(filename string) bool
- func GetNotZeroFields(obj interface{}, fields ...string) []string
- func GetStructTV(obj interface{}) (reflect.Type, reflect.Value, error)
- func IP(validValue interface{}, params ...string) bool
- func InArray(item interface{}, array interface{}) bool
- func IsSatisfied(obj interface{}) bool
- func IsStruct(t reflect.Type) bool
- func IsStructPtr(t reflect.Type) bool
- func Join(arr interface{}, sep string) string
- func JsonPrint(obj interface{})
- func Length(validValue interface{}, params ...string) bool
- func Mac(validValue interface{}, params ...string) bool
- func Max(validValue interface{}, params ...string) bool
- func MaxSize(validValue interface{}, params ...string) bool
- func Md5(str string) string
- func Min(validValue interface{}, params ...string) bool
- func MinSize(validValue interface{}, params ...string) bool
- func Mobile(validValue interface{}, params ...string) bool
- func Numeric(validValue interface{}, params ...string) bool
- func OpenTaskName(validValue interface{}, params ...string) bool
- func RandomString(length int) string
- func Range(validValue interface{}, params ...string) bool
- func Serialize(data interface{}) ([]byte, error)
- func SortSlice(slicePtr interface{}, sortFields string) error
- func Tel(validValue interface{}, params ...string) bool
- func ToSlice(arr interface{}) []interface{}
- func TrimStruct(obj interface{}, field ...string)
- func ZipCode(validValue interface{}, params ...string) bool
- type Request
- type Response
- type Tools
- func (this *Tools) ApiPost(url string, postParams Request) (bodyByte []byte, err error)
- func (this *Tools) GetRequest(requestDat []byte, ret interface{}) error
- func (this *Tools) GetResponse(requestData interface{}) ([]byte, error)
- func (this *Tools) Post(url string, requestData interface{}, response *Response) error
- func (this *Tools) PostUnmarshal(url string, req interface{}, ack interface{}) error
- type ValidFun
- type Validation
- func (this *Validation) FieldTag(fieldTag map[string]string) *Validation
- func (this *Validation) GetStructTV(obj interface{}) (reflect.Type, reflect.Value, error)
- func (this *Validation) InSliceString(field string, arr []string) bool
- func (this *Validation) IsEmpty(obj interface{}) bool
- func (this *Validation) IsStruct(t reflect.Type) bool
- func (this *Validation) IsStructPtr(t reflect.Type) bool
- func (this *Validation) Priority(fields ...string) *Validation
- func (this *Validation) RegisterFun(funcName string, validFunc ValidFun) *Validation
- func (this *Validation) Require(fields ...string) *Validation
- func (this *Validation) SetFailMessages(failMessages map[string]string) *Validation
- func (this *Validation) SetMessageTmpls(messageTmpls map[string]string) *Validation
- func (this *Validation) Valid(obj interface{}) error
- func (this *Validation) ValidAll(obj interface{}) map[string]error
Constants ¶
This section is empty.
Variables ¶
View Source
var MessageTmpls = map[string]string{
"Required": "不能为空",
"Max": "最大为%v",
"Min": "最小为%v",
"Range": "范围为%v到%v",
"MinSize": "最小长度为%v",
"MaxSize": "最大长度为%v",
"Length": "长度必须为%v",
"Alpha": "必须为字母",
"Numeric": "必须为数字",
"AlphaNumeric": "必须为字母、数字",
"AlphaDash": "必须为字母、数字、-或_",
"Email": "必须为有效的邮箱地址",
"IP": "必须为有效的IP地址",
"Mobile": "必须为有效的手机号码",
"Tel": "必须为有效的固定电话",
"ZipCode": "必须是有效的zipcode",
"UploadExt": "文件后缀名只能为 %v",
"UploadSize": "文件大小不能超过 %dMB",
"Mac": "必须是有效的mac地址",
"SpecialChar": "不允许字符包括`~!@#$%^&*()=+[]{}\\|;:.'\",<>/?",
"RuneLength": "不能超过15个字符",
"ChnDash": "只支持数字,字母,汉字,-或_的组合",
"ChnAlphaNumeric": "只支持数字,字母,汉字的组合",
"Chn": "只支持汉字",
"Sensitive": "中包含敏感词:%s,请修改。",
"OpenTaskName": "只支持数字,字母,汉字,-或_或.的组合",
"SubnetMask": "子网掩码必须为有效的IP地址",
}
验证函数未通过,对应的错误提示
Functions ¶
func AESDecrypt ¶
Decrypt from base64 to decrypted string
func AESEncrypt ¶
Encrypt string to base64 crypto using AES
func AlphaNumeric ¶
alpha 字符(字母)或数字,有效类型:string
func GetNotZeroFields ¶
获取结构体的非零值字段
func GetStructTV ¶
获取结构体或者指针的类型和值
Types ¶
type Response ¶
type Response struct { Code uint32 `json:"Code"` //错误码 Version string `json:"Version"` //客户端版本号 Msg string `json:"Msg"` //错误信息 Data []byte `json:"Data"` //响应的ProtoBuf数据 }
响应的数据格式
type Tools ¶
type Tools struct {
Debug bool
}
lwyserver 接口服务
func (*Tools) GetRequest ¶
func (*Tools) GetResponse ¶
func (*Tools) PostUnmarshal ¶
json,协议byte数据
type Validation ¶
type Validation struct {
// contains filtered or unexported fields
}
A Validation context manages data validation and error messages.
func (*Validation) FieldTag ¶
func (this *Validation) FieldTag(fieldTag map[string]string) *Validation
手动设置FieldTag
func (*Validation) GetStructTV ¶
获取结构体或者指针的类型和值
func (*Validation) InSliceString ¶
func (this *Validation) InSliceString(field string, arr []string) bool
判定某个值是否在数组里面
func (*Validation) IsEmpty ¶
func (this *Validation) IsEmpty(obj interface{}) bool
判定一个interface的值是否为空值
func (*Validation) IsStructPtr ¶
func (this *Validation) IsStructPtr(t reflect.Type) bool
判定是否为结构体指针
func (*Validation) Priority ¶
func (this *Validation) Priority(fields ...string) *Validation
设置优先验证字段,可通过此方法调整字段验证顺序
func (*Validation) RegisterFun ¶
func (this *Validation) RegisterFun(funcName string, validFunc ValidFun) *Validation
注册函数
func (*Validation) SetFailMessages ¶
func (this *Validation) SetFailMessages(failMessages map[string]string) *Validation
设定字段出错时的错误消息
func (*Validation) SetMessageTmpls ¶
func (this *Validation) SetMessageTmpls(messageTmpls map[string]string) *Validation
设定函数对应的模板消息
func (*Validation) ValidAll ¶
func (this *Validation) ValidAll(obj interface{}) map[string]error
会验证所有的字段
Click to show internal directories.
Click to hide internal directories.