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
0c31c2d6
authored
2015-02-22 22:13:06 +0500
by
Sergey Shcherbina
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Added support to parse slices of ints and strings in ParseForm func
1 parent
f988f035
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
templatefunc.go
templatefunc.go
View file @
0c31c2d
...
...
@@ -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
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