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
e47b2b67
authored
2013-08-10 11:42:25 +0800
by
miraclesu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Update ParserForm for new form tag style
1 parent
38f6f8ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
utils.go
utils_test.go
utils.go
View file @
e47b2b6
...
...
@@ -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 @
e47b2b6
...
...
@@ -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
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