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
52df1234
Commit
52df1234
authored
Nov 04, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of
https://github.com/astaxie/beego
into develop
parents
fc6b9ce0
b9fdd675
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
6 deletions
+38
-6
templatefunc.go
templatefunc.go
+21
-0
templatefunc_test.go
templatefunc_test.go
+17
-6
No files found.
templatefunc.go
View file @
52df1234
...
@@ -302,6 +302,14 @@ func ParseForm(form url.Values, obj interface{}) error {
...
@@ -302,6 +302,14 @@ func ParseForm(form url.Values, obj interface{}) error {
switch
fieldT
.
Type
.
Kind
()
{
switch
fieldT
.
Type
.
Kind
()
{
case
reflect
.
Bool
:
case
reflect
.
Bool
:
if
strings
.
ToLower
(
value
)
==
"on"
||
strings
.
ToLower
(
value
)
==
"1"
||
strings
.
ToLower
(
value
)
==
"yes"
{
fieldV
.
SetBool
(
true
)
continue
}
if
strings
.
ToLower
(
value
)
==
"off"
||
strings
.
ToLower
(
value
)
==
"0"
||
strings
.
ToLower
(
value
)
==
"no"
{
fieldV
.
SetBool
(
false
)
continue
}
b
,
err
:=
strconv
.
ParseBool
(
value
)
b
,
err
:=
strconv
.
ParseBool
(
value
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -329,6 +337,19 @@ func ParseForm(form url.Values, obj interface{}) error {
...
@@ -329,6 +337,19 @@ func ParseForm(form url.Values, obj interface{}) error {
fieldV
.
Set
(
reflect
.
ValueOf
(
value
))
fieldV
.
Set
(
reflect
.
ValueOf
(
value
))
case
reflect
.
String
:
case
reflect
.
String
:
fieldV
.
SetString
(
value
)
fieldV
.
SetString
(
value
)
case
reflect
.
Struct
:
switch
fieldT
.
Type
.
String
()
{
case
"time.Time"
:
format
:=
time
.
RFC3339
if
len
(
tags
)
>
1
{
format
=
tags
[
1
]
}
t
,
err
:=
time
.
Parse
(
format
,
value
)
if
err
!=
nil
{
return
err
}
fieldV
.
Set
(
reflect
.
ValueOf
(
t
))
}
}
}
}
}
return
nil
return
nil
...
...
templatefunc_test.go
View file @
52df1234
...
@@ -102,12 +102,14 @@ func TestHtmlunquote(t *testing.T) {
...
@@ -102,12 +102,14 @@ func TestHtmlunquote(t *testing.T) {
func
TestParseForm
(
t
*
testing
.
T
)
{
func
TestParseForm
(
t
*
testing
.
T
)
{
type
user
struct
{
type
user
struct
{
Id
int
`form:"-"`
Id
int
`form:"-"`
tag
string
`form:"tag"`
tag
string
`form:"tag"`
Name
interface
{}
`form:"username"`
Name
interface
{}
`form:"username"`
Age
int
`form:"age,text"`
Age
int
`form:"age,text"`
Email
string
Email
string
Intro
string
`form:",textarea"`
Intro
string
`form:",textarea"`
StrBool
bool
`form:"strbool"`
Date
time
.
Time
`form:"date,2006-01-02"`
}
}
u
:=
user
{}
u
:=
user
{}
...
@@ -119,6 +121,8 @@ func TestParseForm(t *testing.T) {
...
@@ -119,6 +121,8 @@ func TestParseForm(t *testing.T) {
"age"
:
[]
string
{
"40"
},
"age"
:
[]
string
{
"40"
},
"Email"
:
[]
string
{
"test@gmail.com"
},
"Email"
:
[]
string
{
"test@gmail.com"
},
"Intro"
:
[]
string
{
"I am an engineer!"
},
"Intro"
:
[]
string
{
"I am an engineer!"
},
"strbool"
:
[]
string
{
"yes"
},
"date"
:
[]
string
{
"2014-11-12"
},
}
}
if
err
:=
ParseForm
(
form
,
u
);
err
==
nil
{
if
err
:=
ParseForm
(
form
,
u
);
err
==
nil
{
t
.
Fatal
(
"nothing will be changed"
)
t
.
Fatal
(
"nothing will be changed"
)
...
@@ -144,6 +148,13 @@ func TestParseForm(t *testing.T) {
...
@@ -144,6 +148,13 @@ func TestParseForm(t *testing.T) {
if
u
.
Intro
!=
"I am an engineer!"
{
if
u
.
Intro
!=
"I am an engineer!"
{
t
.
Errorf
(
"Intro should equal `I am an engineer!` but got `%v`"
,
u
.
Intro
)
t
.
Errorf
(
"Intro should equal `I am an engineer!` but got `%v`"
,
u
.
Intro
)
}
}
if
u
.
StrBool
!=
true
{
t
.
Errorf
(
"strboll should equal `true`, but got `%v`"
,
u
.
StrBool
)
}
y
,
m
,
d
:=
u
.
Date
.
Date
()
if
y
!=
2014
||
m
.
String
()
!=
"November"
||
d
!=
12
{
t
.
Errorf
(
"Date should equal `2014-11-12`, but got `%v`"
,
u
.
Date
.
String
())
}
}
}
func
TestRenderForm
(
t
*
testing
.
T
)
{
func
TestRenderForm
(
t
*
testing
.
T
)
{
...
...
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