File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ Usage and documentation
3434
3535Please see http://godoc.org/gopkg.in/bluesuncorp/validator.v6 for detailed usage docs.
3636
37- ##### Example :
37+ ##### Examples :
3838``` go
3939package main
4040
@@ -73,6 +73,12 @@ func main() {
7373
7474 validate = validator.New (config)
7575
76+ validateStruct ()
77+ validateField ()
78+ }
79+
80+ func validateStruct () {
81+
7682 address := &Address{
7783 Street: " Eavesdown Docks" ,
7884 Planet: " Persphone" ,
@@ -109,6 +115,19 @@ func main() {
109115
110116 // save user to database
111117}
118+
119+ func validateField () {
120+ myEmail := " joeybloggs.gmail.com"
121+
122+ errs := validate.Field (myEmail, " required,email" )
123+
124+ if errs != nil {
125+ fmt.Println (errs) // output: Key: "" Error:Field validation for "" failed on the "email" tag
126+ return
127+ }
128+
129+ // email ok, move on
130+ }
112131```
113132
114133Benchmarks
Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ func main() {
3535
3636 validate = validator .New (config )
3737
38+ validateStruct ()
39+ validateField ()
40+ }
41+
42+ func validateStruct () {
43+
3844 address := & Address {
3945 Street : "Eavesdown Docks" ,
4046 Planet : "Persphone" ,
@@ -71,3 +77,16 @@ func main() {
7177
7278 // save user to database
7379}
80+
81+ func validateField () {
82+ myEmail := "joeybloggs.gmail.com"
83+
84+ errs := validate .Field (myEmail , "required,email" )
85+
86+ if errs != nil {
87+ fmt .Println (errs ) // output: Key: "" Error:Field validation for "" failed on the "email" tag
88+ return
89+ }
90+
91+ // email ok, move on
92+ }
You can’t perform that action at this time.
0 commit comments