Commit 5c859466 authored by miraclesu's avatar miraclesu

ignore struct field if form tag value is '-'

parent 449fbe82
......@@ -195,6 +195,8 @@ func ParseForm(form url.Values, obj interface{}) error {
var tag string
if len(tags) == 0 || len(tags[0]) == 0 {
tag = fieldT.Name
} else if tags[0] == "-" {
continue
} else {
tag = tags[0]
}
......
......@@ -104,8 +104,8 @@ func TestInSlice(t *testing.T) {
func TestParseForm(t *testing.T) {
type user struct {
Id int
tag string `form:tag`
Id int `form:"-"`
tag string `form:"tag"`
Name interface{} `form:"username"`
Age int `form:"age,text"`
Email string
......@@ -114,6 +114,8 @@ func TestParseForm(t *testing.T) {
u := user{}
form := url.Values{
"Id": []string{"1"},
"-": []string{"1"},
"tag": []string{"no"},
"username": []string{"test"},
"age": []string{"40"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment