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
e47b2b67
Commit
e47b2b67
authored
Aug 10, 2013
by
miraclesu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update ParserForm for new form tag style
parent
38f6f8ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
utils.go
utils.go
+7
-2
utils_test.go
utils_test.go
+10
-5
No files found.
utils.go
View file @
e47b2b67
...
...
@@ -190,10 +190,15 @@ func ParseForm(form url.Values, obj interface{}) error {
continue
}
fieldT
:=
objT
.
Field
(
i
)
tag
:=
fieldT
.
Tag
.
Get
(
"form"
)
if
len
(
tag
)
==
0
{
tags
:=
strings
.
Split
(
fieldT
.
Tag
.
Get
(
"form"
),
","
)
var
tag
string
if
len
(
tags
)
==
0
||
len
(
tags
[
0
])
==
0
{
tag
=
fieldT
.
Name
}
else
{
tag
=
tags
[
0
]
}
value
:=
form
.
Get
(
tag
)
if
len
(
value
)
==
0
{
continue
...
...
utils_test.go
View file @
e47b2b67
...
...
@@ -106,8 +106,9 @@ func TestParseForm(t *testing.T) {
Id
int
tag
string
`form:tag`
Name
interface
{}
`form:"username"`
Age
int
`form:"age"`
Age
int
`form:"age
,text
"`
Email
string
Intro
string
`form:",textarea"`
}
u
:=
user
{}
...
...
@@ -116,6 +117,7 @@ func TestParseForm(t *testing.T) {
"username"
:
[]
string
{
"test"
},
"age"
:
[]
string
{
"40"
},
"Email"
:
[]
string
{
"test@gmail.com"
},
"Intro"
:
[]
string
{
"I am an engineer!"
},
}
if
err
:=
ParseForm
(
form
,
u
);
err
==
nil
{
t
.
Fatal
(
"nothing will be changed"
)
...
...
@@ -127,15 +129,18 @@ func TestParseForm(t *testing.T) {
t
.
Errorf
(
"Id should equal 0 but got %v"
,
u
.
Id
)
}
if
len
(
u
.
tag
)
!=
0
{
t
.
Error
(
"tag's length should equal 0 but got %v"
,
len
(
u
.
tag
))
t
.
Error
f
(
"tag's length should equal 0 but got %v"
,
len
(
u
.
tag
))
}
if
u
.
Name
.
(
string
)
!=
"test"
{
t
.
Error
(
"Name should equal `test` but got `%v`"
,
u
.
Name
.
(
string
))
t
.
Error
f
(
"Name should equal `test` but got `%v`"
,
u
.
Name
.
(
string
))
}
if
u
.
Age
!=
40
{
t
.
Error
(
"Age should equal 40 but got %v"
,
u
.
Age
)
t
.
Error
f
(
"Age should equal 40 but got %v"
,
u
.
Age
)
}
if
u
.
Email
!=
"test@gmail.com"
{
t
.
Error
(
"Email should equal `test@gmail.com` but got `%v`"
,
u
.
Email
)
t
.
Errorf
(
"Email should equal `test@gmail.com` but got `%v`"
,
u
.
Email
)
}
if
u
.
Intro
!=
"I am an engineer!"
{
t
.
Errorf
(
"Intro should equal `I am an engineer!` but got `%v`"
,
u
.
Intro
)
}
}
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