Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
ddb9ed39
Commit
ddb9ed39
authored
Jul 22, 2013
by
miraclesu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add validation README
parent
a242f61b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
README.md
validation/README.md
+50
-0
validation_test.go
validation/validation_test.go
+1
-1
No files found.
validation/README.md
0 → 100644
View file @
ddb9ed39
validation
==============
validation is a form validation for a data validation and error collecting using Go.
## Installation and tests
Install:
go get github.com/astaxie/beego/validation
Test:
go test github.com/astaxie/beego/validation
## Example
import (
"github.com/astaxie/beego/validation"
"log"
)
type User struct {
Name string
Age int
}
func main() {
u := User{"man", 40}
valid := validation.Validation{}
valid.Required(u.Name, "name")
valid.MaxSize(u.Name, 15, "nameMax")
valid.Range(u.Age, 0, 140, "age")
if valid.HasErrors {
// validation does not pass
// print invalid message
for _, err := range valid.Errors {
log.Println(err.Key, err.Message)
}
}
// or use like this
if v := valid.Max(u.Age, 140); !v.Ok {
log.Println(v.Error.Key, v.Error.Message)
}
}
## LICENSE
BSD License http://creativecommons.org/licenses/BSD/
validation/validation_test.go
View file @
ddb9ed39
...
...
@@ -31,7 +31,7 @@ func TestRequired(t *testing.T) {
t
.
Error
(
"empty slice should be false"
)
}
if
!
valid
.
Required
([]
interface
{}{
"ok"
},
"slice"
)
.
Ok
{
t
.
Error
(
"slice should
be equal
true"
)
t
.
Error
(
"slice should
be
true"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment