Skip to content

dabao-zhao/validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

validation

安装

go get github.com/dabao-zhao/validation@latest

使用

c := Customer{
    Name:  "dabao",
    Email: "977904037@qq.com",
    Address: Address{
        Street: "5",
        City:   "Beijing",
        State:  "Beijing",
        Zip:    "0000000",
    },
}
valid := validation.Make(&c,
    validation.Field(&c.Address, rules.Required),
    validation.Field(&c.Address.City, rules.Required, rules.Length(20, 100)),
    validation.Field(&c.Address.Street, rules.Required, rules.RuneLength(20, 1000)),
)

err := valid.Validate()
c := map[string]interface{}{
    "name":  "dabao",
    "email": "977904037@qq.com",
    "address": map[string]interface{}{
        "street": "5",
        "city":   "Beijing",
        "state":  "Beijing",
        "zip":    "0000000",
    },
}
valid := validation.Make(&c,
    validation.Field("address", rules.Required),
    validation.Field("address.city", rules.Required, rules.Length(20, 100)),
)

err := valid.Validate()

灵感来源于

ozzo-validation,同时也使用了该库的很多方法

About

a package for go validation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages