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
b191e96f
Commit
b191e96f
authored
Aug 06, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #125 from miraclesu/valid
Change tag valid func default key
parents
f9a31ea0
97d99fce
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
util.go
validation/util.go
+3
-3
validation_test.go
validation/validation_test.go
+14
-0
No files found.
validation/util.go
View file @
b191e96f
...
...
@@ -120,7 +120,7 @@ func getRegFuncs(tag, key string) (vfs []ValidFunc, str string, err error) {
if
err
!=
nil
{
return
}
vfs
=
[]
ValidFunc
{
ValidFunc
{
"Match"
,
[]
interface
{}{
reg
,
key
}}}
vfs
=
[]
ValidFunc
{
ValidFunc
{
"Match"
,
[]
interface
{}{
reg
,
key
+
".Match"
}}}
str
=
strings
.
TrimSpace
(
tag
[
:
index
])
+
strings
.
TrimSpace
(
tag
[
end
+
len
(
"/)"
)
:
])
return
}
...
...
@@ -145,7 +145,7 @@ func parseFunc(vfunc, key string) (v ValidFunc, err error) {
err
=
fmt
.
Errorf
(
"%s require %d parameters"
,
vfunc
,
num
)
return
}
v
=
ValidFunc
{
vfunc
,
[]
interface
{}{
key
}}
v
=
ValidFunc
{
vfunc
,
[]
interface
{}{
key
+
"."
+
vfunc
}}
return
}
...
...
@@ -167,7 +167,7 @@ func parseFunc(vfunc, key string) (v ValidFunc, err error) {
return
}
tParams
,
err
:=
trim
(
name
,
key
,
params
)
tParams
,
err
:=
trim
(
name
,
key
+
"."
+
name
,
params
)
if
err
!=
nil
{
return
}
...
...
validation/validation_test.go
View file @
b191e96f
...
...
@@ -298,6 +298,7 @@ func TestValid(t *testing.T) {
}
uptr
:=
&
user
{
Name
:
"test"
,
Age
:
40
}
valid
.
Clear
()
b
,
err
=
valid
.
Valid
(
uptr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -305,8 +306,15 @@ func TestValid(t *testing.T) {
if
b
{
t
.
Error
(
"validation should not be passed"
)
}
if
len
(
valid
.
Errors
)
!=
1
{
t
.
Fatalf
(
"valid errors len should be 1 but got %d"
,
len
(
valid
.
Errors
))
}
if
valid
.
Errors
[
0
]
.
Key
!=
"Name.Match"
{
t
.
Errorf
(
"Message key should be `Name.Match` but got %s"
,
valid
.
Errors
[
0
]
.
Key
)
}
u
=
user
{
Name
:
"test@/test/;com"
,
Age
:
180
}
valid
.
Clear
()
b
,
err
=
valid
.
Valid
(
u
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -314,4 +322,10 @@ func TestValid(t *testing.T) {
if
b
{
t
.
Error
(
"validation should not be passed"
)
}
if
len
(
valid
.
Errors
)
!=
1
{
t
.
Fatalf
(
"valid errors len should be 1 but got %d"
,
len
(
valid
.
Errors
))
}
if
valid
.
Errors
[
0
]
.
Key
!=
"Age.Range"
{
t
.
Errorf
(
"Message key should be `Name.Match` but got %s"
,
valid
.
Errors
[
0
]
.
Key
)
}
}
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