update README
Showing
1 changed file
with
49 additions
and
0 deletions
| ... | @@ -15,6 +15,8 @@ Test: | ... | @@ -15,6 +15,8 @@ Test: |
| 15 | 15 | ||
| 16 | ## Example | 16 | ## Example |
| 17 | 17 | ||
| 18 | Direct Use: | ||
| 19 | |||
| 18 | import ( | 20 | import ( |
| 19 | "github.com/astaxie/beego/validation" | 21 | "github.com/astaxie/beego/validation" |
| 20 | "log" | 22 | "log" |
| ... | @@ -44,6 +46,53 @@ Test: | ... | @@ -44,6 +46,53 @@ Test: |
| 44 | } | 46 | } |
| 45 | } | 47 | } |
| 46 | 48 | ||
| 49 | Struct Tag Use: | ||
| 50 | |||
| 51 | import ( | ||
| 52 | "github.com/astaxie/beego/validation" | ||
| 53 | ) | ||
| 54 | |||
| 55 | // validation function follow with "valid" tag | ||
| 56 | // functions divide with ";" | ||
| 57 | // parameters in parentheses "()" and divide with "," | ||
| 58 | type user struct { | ||
| 59 | Id int | ||
| 60 | Name string `valid:"Required"` | ||
| 61 | Age int `valid:"Required;Range(1, 140)"` | ||
| 62 | } | ||
| 63 | |||
| 64 | func main() { | ||
| 65 | valid := Validation{} | ||
| 66 | u := user{Name: "test", Age: 40} | ||
| 67 | b, err := valid.Valid(u) | ||
| 68 | if err != nil { | ||
| 69 | // handle error | ||
| 70 | } | ||
| 71 | if !b { | ||
| 72 | // validation does not pass | ||
| 73 | // blabla... | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | Struct Tag Functions: | ||
| 78 | |||
| 79 | Required | ||
| 80 | Min(min int) | ||
| 81 | Max(max int) | ||
| 82 | Range(min, max int) | ||
| 83 | MinSize(min int) | ||
| 84 | MaxSize(max int) | ||
| 85 | Length(length int) | ||
| 86 | Alpha | ||
| 87 | Numeric | ||
| 88 | AlphaNumeric | ||
| 89 | Match(regexp string) // does not support yet | ||
| 90 | NoMatch(regexp string) // does not support yet | ||
| 91 | AlphaDash | ||
| 92 | |||
| 93 | IP | ||
| 94 | Base64 | ||
| 95 | |||
| 47 | 96 | ||
| 48 | ## LICENSE | 97 | ## LICENSE |
| 49 | 98 | ... | ... |
-
Please register or sign in to post a comment