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
0c31c2d6
Commit
0c31c2d6
authored
Feb 22, 2015
by
Sergey Shcherbina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support to parse slices of ints and strings in ParseForm func
parent
f988f035
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
templatefunc.go
templatefunc.go
+21
-0
No files found.
templatefunc.go
View file @
0c31c2d6
...
...
@@ -358,11 +358,32 @@ func ParseForm(form url.Values, obj interface{}) error {
}
fieldV
.
Set
(
reflect
.
ValueOf
(
t
))
}
case
reflect
.
Slice
:
if
fieldT
.
Type
==
sliceOfInts
{
formVals
:=
form
[
tag
]
fieldV
.
Set
(
reflect
.
MakeSlice
(
reflect
.
SliceOf
(
reflect
.
TypeOf
(
int
(
1
))),
len
(
formVals
),
len
(
formVals
)))
for
i
:=
0
;
i
<
len
(
formVals
);
i
++
{
val
,
err
:=
strconv
.
Atoi
(
formVals
[
i
])
if
err
!=
nil
{
return
err
}
fieldV
.
Index
(
i
)
.
SetInt
(
int64
(
val
))
}
}
else
if
fieldT
.
Type
==
sliceOfStrings
{
formVals
:=
form
[
tag
]
fieldV
.
Set
(
reflect
.
MakeSlice
(
reflect
.
SliceOf
(
reflect
.
TypeOf
(
""
)),
len
(
formVals
),
len
(
formVals
)))
for
i
:=
0
;
i
<
len
(
formVals
);
i
++
{
fieldV
.
Index
(
i
)
.
SetString
(
formVals
[
i
])
}
}
}
}
return
nil
}
var
sliceOfInts
=
reflect
.
TypeOf
([]
int
(
nil
))
var
sliceOfStrings
=
reflect
.
TypeOf
([]
string
(
nil
))
var
unKind
=
map
[
reflect
.
Kind
]
bool
{
reflect
.
Uintptr
:
true
,
reflect
.
Complex64
:
true
,
...
...
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