Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
ddb9ed39
authored
2013-07-22 17:40:32 +0800
by
miraclesu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add validation README
1 parent
a242f61b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletions
validation/README.md
validation/validation_test.go
validation/README.md
0 → 100644
View file @
ddb9ed3
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 @
ddb9ed3
...
...
@@ -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
Styling with
Markdown
is supported
Attach a file
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 post a comment