superChecker

package module
v0.0.0-...-e0fbd77 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2019 License: MIT Imports: 12 Imported by: 1

README

Table of Contents generated with DocToc

1. Start

go get github.com/fwhezfwhez/SuperChecker

2. Tips

2.1 The tag 'superChecker' has stopped developing

the tag 'superChecker' is abandoned and replaced by tag 'validate'. Old usages are remained, function is still access if you insist on using this.More usages refer to Example

type U struct{
Username string `superChecker:"username"`
}
2.2 There are some built-in regex key, case-not-sensitive
key regex desc
chineseOnly ^[\u4E00-\u9FA5]*$ only chinese format
notNull ^[\s\S]+$ not empty
username ^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$ chinese,a-z,A-Z,0-9,_,. len 0-40
number ^[0-9]+$ number more than one bit
decimal ^\d+\.[0-9]+$ number
mobilePhone ^1[0-9]{10}$ 10 bit mobile phone
telephone ^[0-9]{8}$ 8 bit telephone
2.3 regex key combining

logic 'and' and 'or' key1,key2,key3 ... the value should fit all of the keys key1|key2|key3 ... the value should fit one of the keys

not supported:

  • key1,key2,key3|key4,key5|key6 use ',' '|' together not supported
  • key1,key2,(key3,key4) use '()' is not supported
type U struct{
Username string `superChecker:"username,notNull"`
Username2 string `validate:"regex,username,notNull"`
Username3 string `superChecker:"username|notNull"`
Username4 string `validate:"regex,username|notNull"`
}

3. Example

3.1 superChecker tag example(this tag is stoped developing,and replaced by validate, the old usage is still access)
// Tips:
// 'superChecker' tag has been stopped developing, the old functions will be remained.
// 'validate' tag is to replace the old ussages:
// "Name string `superChecker:"key1,key2"`" equals to "Name string `validate:"regex,key1,key2"`"

package main

import (
    "fmt"
    "github.com/shopspring/decimal"
    "github.com/fwhezfwhez/SuperChecker"
)

type Animal struct{
    Name string `superChecker:"username"`
    Count int `superChecker:"positive"`
    Price decimal.Decimal `superChecker:"positive"`
}

func main() {
    animal := Animal{
        Name:"beibei",
        Count: 1000,
        Price: decimal.NewFromFloat(100000),
    }

    checker := superChecker.GetChecker()
    checker.AddRegex("username","^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$")
    checker.AddRegex("positive","^[0-9.]+$")
    ok,msg,er := checker.SuperCheck(animal)
    if er!=nil {
        fmt.Println(fmt.Sprintf("got an error: '%s'", er.Error()))
        return
    }
    if !ok {
        fmt.Println(fmt.Sprintf("fail because of : '%s'", msg))
        return
    }
    fmt.Println("success")
}
3.2 validate tag example
package main

import (
    "fmt"
    "github.com/shopspring/decimal"
    "github.com/fwhezfwhez/SuperChecker"
    "time"
)

type Order struct {
    // TIME
    CreatedAt time.Time `validate:"time.time"`
    UpdatedAt string    `validate:"time.time,2006/01/02 15:04:05"`

    // INT
    Count    int `validate:"int,0:200"`
    MaxCount int `validate:"int,:200"`
    MinCount int `validate:"int,10:"`
    Count2   int `validate:"int64,0:200"`

    // FLOAT
    RewardRate    float64         `validate:"float,0:0.4"`
    MaxRewardRate float64         `validate:"float,:0.4"`
    MinRewradRate float64         `validate:"float,0:"`
    RewardRate2   float64         `validate:"float64,0:0.4"`
    RewardRate3   decimal.Decimal `validate:"decimal,0:0.4"`

    // REGEX
    OrderUsername  string `validate:"regex,^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$"`
    OrderUsername2 string `validate:"regex,username"`

    // RANGE,IN
    OrderStatus     int    `validate:"range,[1,2,3,4]"`
    OrderStatusName string `validate:"in,[unpaid,paid,closed]"`

    // FUNC, FUNCTION
    MailTypeCheckBox  string `validate:"func,inAndLength,lengthMoreThan3"`
    MailTypeCheckBox2 string `validate:"function,lengthLessThan3|inAndLength"`
}
func (o Order) XXSVValidateSVBCreate()(bool,string,error){
    return true,"xxsvcreate wrong",nil
}
func (o Order) XXValidate()(bool,string,error){
    return true,"xxv wrong",nil
}
func (o Order) XXSVValidate()(bool,string,error){
    return true,"xxsv wrong",nil
}

func (o Order) XXValidateSVBCreate()(bool,string,error){
    return true,"xxcreate wrong",nil
}



func (o Order) XXValidateSVBCreateSVSUpdate()(bool,string,error){
    return false,"xxsvcreateupdate wrong",nil
}
func (o Order) XXSVValidateSVBCreateSVSUpdate()(bool,string,error){
    return true,"xxsvcreateupdate wrong",nil
}

func main() {
    order := Order{
        CreatedAt: time.Now(),
        UpdatedAt: time.Now().Format("2006/01/02 15:04:05"),

        Count:    200,
        MaxCount: 90,
        MinCount: 10,
        Count2:   100,

        RewardRate:    0.4,
        MaxRewardRate: 0.3,
        MinRewradRate: 0.1,
        RewardRate2:   0.1,
        RewardRate3:   decimal.NewFromFloat(0.4),

        OrderUsername:  "superCheckerValidate",
        OrderUsername2: "superCheckerValidate",

        OrderStatus:     3,
        OrderStatusName: "closed",

        MailTypeCheckBox:  "midMail",
        MailTypeCheckBox2: "midMail",
    }

    checker := superChecker.GetChecker()
    checker.AddFunc(func(in interface{}, fieldName string) (bool, string, error) {
        v := superChecker.ToString(in)
        maxLength := 7
        if len(v) > maxLength {
            return false, fmt.Sprintf("while validating field '%s', rule key '%s' over length,want %d ,but got %d", fieldName, "inAndLength", maxLength, len(v)), nil
        }
        vrange := []string{"midMail", "shenMail", "yundaMail"}
        for _, value := range vrange {
            if value == v {
                return true, "success", nil
            }
        }
        return false, fmt.Sprintf("while validating field '%s', rule key '%s',  value '%s' not in '%v'", fieldName, "inAndLength", v, vrange), nil
    }, "inAndLength")
    checker.AddFunc(func(in interface{}, fieldName string)(bool, string, error){
        v := superChecker.ToString(in)
        minLength := 3
        if len(v) < minLength {
            return false, fmt.Sprintf("while validating field '%s', rule key '%s' too short length,want %d ,but got %d", fieldName, "inAndLength", minLength, len(v)), nil
        }
        return true, "success", nil
    },"lengthmorethan3")

    checker.AddFunc(func(in interface{}, fieldName string)(bool, string, error){
        v := superChecker.ToString(in)
        maxLength := 3
        if len(v) > maxLength {
            return false, fmt.Sprintf("while validating field '%s', rule key '%s' too short length,want %d ,but got %d", fieldName, "inAndLength", maxLength, len(v)), nil
        }
        return true, "success", nil
    },"lengthlessthan3")

    ok, msg, er := checker.Validate(order)
    if er != nil {
        fmt.Println(fmt.Sprintf("got an error, '%s'", er.Error()))
        return
    }
    if !ok {
        fmt.Println(fmt.Sprintf("validate fail because of '%s'", msg))
        return
    }


    // ioc, inverse of control
    // validate to combine as receiver to the dest struct
    ok, msg, er = checker.ValidateMethods(order,"create","update")
    if er != nil {
        fmt.Println(fmt.Sprintf("got an error, '%s'", er.Error()))
        return
    }
    if !ok {
        fmt.Println(fmt.Sprintf("validate fail because of '%s'", msg))
        return
    }
    fmt.Println("success")
}

4. FAQ

4.1 How to specific superchecker tag?

superChecker(abandoned): The tag value is the key added by AddRegex or AddDefaultRegex, while the former one is the added pool which has higher privalage than the latter one(when both of them has a key 'password', than use the regex in added pool).

   type User struct {
    Password string `superChecker:"password"
   }
   ...
   checker.AddRegex("password", "^[\\s\\S]{6,}$")

When a field will fit several regex rules, use it like

   type User struct {
    Phone string `superChecker:"phone|mobilePhone"
    Introduction string `superChecker:"length,noAbuse,noChinese"`
   }
   checker.AddRegex("phone",  "^[0-9]{8}$")
   checker.AddRegex("mobilePhone","^1[0-9]{10}$")
   ...

key1|key2|key3 means the field(Phone) should fit one of keys(phone,mobilePhone), the or logic. key1,key2,key3 means the field(Introduction) should both fit all of the keys(length,noAbuse,noChinese)

I'm sorry but checker doesn't support '|' and ',' mixed like key1,key2|key3, also doesn't support quoted like 'key1,key2,(key3,key4)'. Soon the checker will give its solutions to this situation

4.2 How to specific validate tag?

validate: The tag value consists of two parts, type and rule(key).Let's see it in table below

type rule/key desc
int/int8/int16/int32/int64, float/float32/float64/decimal 0:100 int value between 0 and 100, containing 0 and 100
int/int8/int16/int32/int64 0: int value bigger than 0, containing 0
time.time 2006/01/02 15:04:05 received time value should be formated like yyyy/MM/dd HH:mm:ss, struct type is string or time.Time or jsoncrack.Time, if is jsoncrack.Time or time.Time, the rule can be ignored like "CreatedAt time.Time `validate:"time.time"`" or just ignore tag "CreatedAt time.Time"
regex ^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$ value should be pass this regex validate, value should be string-able types(int,float,time,fmt.Stringer)
regex username value should pass an in-built or after-added regex key 'username', value should be string-able types(int,float,time,fmt.Stringer), make sure using "checker.AddRegex("username","^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$") before you use this key"
func/function lengthlt10 value should be less than length by 10, make sure using "checker.AddFunc()"
range/in [1,2,3,4]/[paid,unpaid,retreat] value should be contained in the list

type and rule used like:

    type User struct {
        Age int `validate:"int,0:200"` // age should be integer and between 0 and 200
        // Age int `validate:"int,:200"`  // age should be integer and less than 200
        // Age int `validate:"int,0:"`  // age should be integer and bigger than 0

        Salary float64 `validate:"float,0:1000000000"` // Salary  should be float type(float32,float64) and between 0 and 1000000000
        // Salary float64 `validate:"float,:1000000000"`  // Salary  should be float type(float32,float64) and less than 1000000000
        // Salary float64 `validate:"float,0:"`  // Salary  should be float type(float32,float64) and bigger than 0

        // InTime    time.Time       `validate:"time.Time"`// golang support deliver the origin time type ,it's good to use time.Time field to bind data
        // if insist on using string type to bind time data,use it like:
        InTimeStr string `validate:"time.Time,2006.01.2 15:04:05"` // InTimeStr should fit the format '2006.01.2 15:04:05'
    }

The tag value like 'time.Time','int','float' is the type ,and the latter string words is its rule,like '0:200'. int means int type ,it's ok to write like:

...
Age `validate:"int,:120"`
//Age `validate:"int8,:120"`
//Age `validate:"int16,:120"`
//Age `validate:"int32,:120"`
//Age `validate:"int64,:120"`

so does float types

...
Salary `validate:"float,:120"`
//Salary `validate:"float32,:120"`
//Salary `validate:"float64,:120"`
//Salary `validate:"decimal,:120"`
4.3 How to design a function to validate data?

** normal **: addFunc(f func(in interface{}, fieldName string)(bool, string, error), key)

...
type User struct {
    Introduce    string       `validate:"func,introduction"`
}
...
    checker.AddFunc(func(in interface{}, fieldName string) (bool, string, error) {
        v, ok := in.(string)
        if !ok {
            return false, "assertion error,in is not a string type", errors.New("assertion error,in is not a string type")
        }
        // deal with v
        // length limit
        if len(v) > 1000 {
            return false, fmt.Sprintf("max len is 1000,but got %d", len(v)), nil
        }
        // abuse words limit
        if strings.Contains(v, "fuck") {
            return false, fmt.Sprintf("'%s' contains bad words '%s'", v, "fuck"), nil
        }
        return true, "success", nil
    }, "introduction")
...

with path: addFunc(f func(in interface{}, fieldName string)(bool, string, error), key string, path string) the path is combined with a function where it's declared, used to help developer to locate where it is well set.

...
type User struct {
    Introduce    string       `validate:"func,introduction"`
}
...
    _, file, line, _ := runtime.Caller(1)
    path = fmt.Sprintf("%s:%d", file, line)
    checker.AddFunc(func(in interface{}, fieldName string) (bool, string, error) {
        v, ok := in.(string)
        if !ok {
            return false, "assertion error,in is not a string type", errors.New("assertion error,in is not a string type")
        }
        // deal with v
        // length limit
        if len(v) > 1000 {
            return false, fmt.Sprintf("max len is 1000,but got %d", len(v)), nil
        }
        // abuse words limit
        if strings.Contains(v, "fuck") {
            return false, fmt.Sprintf("'%s' contains bad words '%s'", v, "fuck"), nil
        }
        return true, "success", nil
    }, "introduction", path)
...
4.4 How to validate a model by its method and the model as receiver

Some concepts:

concept short for what example declared typs(case-not-sensitive) desc
SVValidate super validate func (o Object) ObjectSVValidate()(bool,string,error) all to declare the method is marked to be validated by checker.ValidateMethods(o) , sv can be ignored, ObjectSVValidate equals to ObjectValidate
SVB super validate begin func (o Object) ObjectSVValidateSVBCreate()(bool,string,error) create to declare a marked method begin spot,after 'SVB' is the typs checker.ValidateMethods(o, "create")
SVS super validate seperate func (o Object) ObjectSVValidateSVBCreateSVSUpdate()(bool,string,error) create, update to seperate 'typs' after 'SVB',checker.ValidateMethods(o, "create", "update")

details:

  • typs choose which methods to be validate, they follow the HIT rule, [create, update] hits [ValidateSVBCreate, SVValidateSVBCreateSVSUpdate, Validate, ValidateSVBUpdate]
  • typs are case-not-sensitive

example:

type O struct {
    Username string
}

// v1
func (o O) OLengthValidate() (bool, string, error) {
    if o.Username > 5 && o.Username < 100 {
        return true, "success", nil
    }
    return false, "length should be between 5 and 100", nil
}

// v2
func (o O) OValidateSVBCreate() (bool, string, error) {
    if o.Username != "" {
        return true, "success", nil
    }
    return false, "length should be between 5 and 100", nil
}

// v3
func (o O) OValidateSVBUpdate() (bool, string, error) {
    if o.Username == "admin" {
        return false, "admin should not be updated", nil
    }
    return true, "success", nil
}

// v4
func (o O) OValidateSVBUpdateSVSCreate() (bool, string, error) {
    if o.Username == "admin" {
        return false, "admin should not be updated", nil
    }
    return true, "success", nil
}
func main() {
    ...
    // o:=O{Username:"he"}
    o := O{Username: "hellworld"}
    // v1 will be validated
    ok, msg, e := checker.ValidateMethods(o)

    // v1,v2,v4 will be validated
    ok, msg, e = checker.ValidateMethods(o, "create")

    // v1,v3,v4 will be validated
    ok, msg, e := checker.ValidateMethods(o, "update")

    // v1,v2,v3,v4 will all be validated
    ok, msg, e := checker.ValidateMethods(o, "update", "create")

    if e != nil {
        handle(e)
    }
    fmt.Println(ok, msg)
}
4.5 validate data without adding tags(using existed tag key).
func main() {
    type User struct{
        Username string `json:"username"`
        Age int `json:"age"`
    }
    var req = User{
        Username: "superchecker",
        Age:-1,
    }
    sp := superChecker.GetChecker()
    ok, msg, e := sp.ValidateByTagKeyAndMapValue(req, "json", map[string]string{
        "username": "regex,^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$",
        "age": "int,0:200",
    })
    fmt.Println(ok, msg, e)
}

More tips on developing and if you want to help contribute,please fork and pull request. More issues please hand in in issue part.3q

Documentation

Index

Constants

View Source
const (
	DEBUG   = 1
	RELEASE = 2
)

Variables

This section is empty.

Functions

func ChineseOnly

func ChineseOnly(data interface{}, fieldName string) (bool, string, error)

only accept 'data' to be chinese use it like:

type User struct{
    ChineseName string `validate:"func,chineseOnly"`
}
func main(){
    user := User{ChineseName: "ft"}
    checker := superChecker.GetChecker()
    checker.AddFunc(superChecker.ChineseOnly, "chineseOnly")
    ok,msg,er :=checker.Validate(user)
	   if er!=nil {
       panic(er)
    }
    if !ok {
        fmt.Println(msg)
        return
    }
    fmt.Println("success")
}

func IsFloat

func IsFloat(in string) bool

float type assertion

func IsInt

func IsInt(in string) bool

int type assertion

func RemovePrefix

func RemovePrefix(s string, prefix string) string

func SmartPrint

func SmartPrint(i interface{})

SmartPrint pretty format print an input value,which should be a struct

func ToString

func ToString(arg interface{}, timeFormat ...string) string

ToString Change arg to string

Types

type Checker

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

global checker object a checker contains its rule which stores the regex rule pool of the default pool and the added pool

func GetChecker

func GetChecker() *Checker

get a checker object which has contained regex rule below: username : ^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$ number : "^[0-9]+$" decimal : "^\\d+\\.[0-9]+$" mobile phone : "^1[0-9]{10}$" telephone : "^[0-9]{8}$" notnull: "^[\\s\\S]+$"

func (*Checker) AddDefaultRegex

func (checker *Checker) AddDefaultRegex(key string, regex string) error

add default regex rule into default pool , when the key is already existed, then it will be replaced by the new one

func (*Checker) AddFunc

func (checker *Checker) AddFunc(f func(in interface{}, fieldName string) (bool, string, error), keyAndPath ...string) error

add a func into func pool keyAndPath stands for the func's key and func's define path. key must specific and must be keyAndPath[0], path is optional. when the length of keyAndPath is 0 or >2 , then throws error. when the length of keyAndPath is 1, key is keyAndPath[0], path is the caller stack depth 1. when the length of keyAndPath is 2, key is keyAndPath[0], path is keyAndPath[1].

func (*Checker) AddRegex

func (checker *Checker) AddRegex(key string, regex string) error

add regex into added pool.

func (*Checker) Check

func (checker *Checker) Check(input string, regex string) (bool, error)

check an input string value by a raw regex string

func (*Checker) CheckFromPool

func (checker *Checker) CheckFromPool(input string, key string) (bool, error)

check an input string value by the compiled regex object from the checker's default and added pool

func (*Checker) ContainFunc

func (checker *Checker) ContainFunc(key string) bool

whether the func pool contains the func key

func (*Checker) FormatCheck

func (checker *Checker) FormatCheck(input interface{}) (bool, string, error)

validate if an input value is correct or not notice:

  1. some ignored cases: `validate:""`, `validate:"-"` will be ignored struct{name string}{name:"undefine"}, struct{name string}{name:"undefined"} will be ignored

support int types ,float types, string, time

func (*Checker) GetDefaultBuilder

func (checker *Checker) GetDefaultBuilder() map[string]*regexp.Regexp

get the default pool

func (*Checker) GetFunc

func (checker *Checker) GetFunc(key string) Func

get func by key

func (*Checker) GetRule

func (checker *Checker) GetRule(key string) string

get a regex string format, added pool has higher privilege

func (*Checker) IsBuilderContainKey

func (checker *Checker) IsBuilderContainKey(key string) bool

whether the added pool contains the rule key

func (*Checker) IsContainKey

func (checker *Checker) IsContainKey(key string) bool

whether the key is contained

func (*Checker) ListAll

func (checker *Checker) ListAll()

list all regex compiled in both the default and the added pool.

func (*Checker) ListDefault

func (checker *Checker) ListDefault()

list default pool

func (*Checker) ListRegexBuilder

func (checker *Checker) ListRegexBuilder()

list added pool

func (*Checker) RemoveRegex

func (checker *Checker) RemoveRegex(key string)

remove regex kv from the added pool.

func (*Checker) SetMode

func (checker *Checker) SetMode(mode int)

set its mode of superChecker.DEBUG,superChecker.RELEASE DEBUG =1 RELEASE = 2

func (*Checker) SuperCheck

func (checker *Checker) SuperCheck(input interface{}) (bool, string, error)

Latest version has stop this's developing replaced by functions like 'FormatCheck' 'Validate' 'ValidateMethods' which alias with tag 'validate' However the old usages are remained, function is access if you insist on using it

support for string input or type that can be transfer to a string or an object which has function String(). notice:

  1. the value of tag 'superCheck' can be either upper or lower or mixed, `superChecker:"username"`,`superChecker:"usERName"` are ok
  2. some cases will be ignored: `superChecker:""`, `superChecker:"-"` will be ignored struct{name string}{name:"undefined"}, struct{name string}{name:"undefine"} will be ignored
  3. make sure the not-ignored fields is string-able, these types can be well stringed: [int,int8,int16,int32,int64,float32,float64,] || <object'function String()>

func (*Checker) Validate

func (checker *Checker) Validate(input interface{}) (bool, string, error)
validate the tag whose key named 'validate'

the same as FormatCheck,but sounds more specific

func (*Checker) ValidateByTagKeyAndMapValue

func (checker *Checker) ValidateByTagKeyAndMapValue(dest interface{}, tagKey string, tags map[string]string) (bool, string, error)

This method is used for the case when dest struct has no 'validate' tag and tag value. Tag name can be specific,like 'json'.

tagKey value should be single `json:""username` or 'username' as its first word splitting by ',' these tags are ok `json:"username"`, `json:"username,x"`, `json:"username,x,y,z,n,m,q"

type User struct{
    Username string `json:"username"`
}

user := User{ Username:"LiLei" } checker := SuperChecker.GetChecker() ok,msg,e:=checker.ValidateByTagKeyAndMapValue(user, "json", map[string]string{ "username": "regex,^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$")} fmt.Println(ok, msg, e)

func (*Checker) ValidateMethods

func (checker *Checker) ValidateMethods(input interface{}, typ ...string) (bool, string, error)

validate a struct methods whose method name ends with '"SVValidate"+<typ flags>'. typ is short for 'type' to avoid the built-in word type. what the string 'typ' stands for? assume you are going to validate a struct User{Username string , Age int}, when creating a new user, 'username' field is required, however when updating a user,'username' is optional. typ helps to tell which method validates on which case. For example: func (o O) UserSVValidateSVBCreate()(bool,string,error){ } SV means 'Super Validate' ,which tells the checker this method will be checked when call ValidateMethods. SVB means 'Super Validate Begin', which tells the checker to identify the typ flags. in the example above, 'typ' is 'Create',and this method only works for 'checker.ValidateMethods(o, 'Create')' func (o O) UserSVValidateSVBCreateSVSUpdate()(bool,string,error){ } SV means 'Super Validate' ,which tells the checker this method will be checked when call ValidateMethods. SVB means 'Super Validate Begin', which tells the checker to identify the typ flags. SVS meas 'Super Validate Separate', which takes typ flags apart. in the example above, this method only works for 'checker.ValidateMethods(o, 'Create', 'Update')'. if typ is not set, all methods which end with 'Validate' or 'SVValidate' will be well checked

func (*Checker) ValidateOne

func (checker *Checker) ValidateOne(typeName string, value interface{}, tagValue string) (bool, string, error)

type Func

type Func struct {
	Value func(in interface{}, filedName string) (bool, string, error)
	Path  string
}

Func has a value and its desgin path.

value serves for a self design function that deals with the input data 'in interface{}', and returns its result 'ok bool',
'message string', 'e error'.
path serves for logging where the function is design

for example:

    value:
    func ValideMoney(in interface{}) (bool,string,error){
	        v, ok :=in.(float64)
         if !ok{
             return false, fmt.Sprintf( want float64 type, got '%v'", in), errors.New(fmt.Sprintf(" want float64 type, got '%v'", in))
         }
	    	return true,"success",nil
    }
   path:
   xxx/xxx/xx/main.go: 90

type Ruler

type Ruler struct {
	RegexBuilder map[string]*regexp.Regexp

	Funcs map[string]Func
	// contains filtered or unexported fields
}

rule object contained in a checker,it consists of a default pool and an added pool

type T

type T struct {
	UserName string `superChecker:"userName"`
	Password string `superChecker:"password"`
	Phone    string `superChecker:"mobilephone|telephone"`
	Text     string `superChecker:"length,chineseOnly"`
}

type T2

type T2 struct {
	CreatedAt         time.Time       `validate:"time.time"`
	UpdatedAt         string          `validate:"time.time,2006/01/02 15:04:05"`
	Count             int             `validate:"int,0:200"`
	MaxCount          int             `validate:"int,:200"`
	MinCount          int             `validate:"int,10:"`
	Count2            int             `validate:"int64,0:200"`
	RewardRate        float64         `validate:"float,0:0.4"`
	MaxRewardRate     float64         `validate:"float,:0.4"`
	MinRewradRate     float64         `validate:"float,0:"`
	RewardRate2       float64         `validate:"float64,0:0.4"`
	RewardRate3       decimal.Decimal `validate:"decimal,0:0.4"`
	OrderUsername     string          `validate:"regex,^[\u4E00-\u9FA5a-zA-Z0-9_.]{0,40}$"`
	OrderUsername2    string          `validate:"regex,username"`
	OrderStatus       int             `validate:"range,[1,2,3,4]"`
	OrderStatusName   string          `validate:"in,[unpaid,paid,closed]"`
	MailTypeCheckBox  string          `validate:"func,inAndLength"`
	MailTypeCheckBox2 string          `validate:"function,inAndLength"`
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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