mirror of
https://github.com/astaxie/beego.git
synced 2024-11-05 01:10:55 +00:00
ignore struct field if form tag value is '-'
This commit is contained in:
parent
449fbe82f6
commit
5c859466ef
2
utils.go
2
utils.go
@ -195,6 +195,8 @@ func ParseForm(form url.Values, obj interface{}) error {
|
|||||||
var tag string
|
var tag string
|
||||||
if len(tags) == 0 || len(tags[0]) == 0 {
|
if len(tags) == 0 || len(tags[0]) == 0 {
|
||||||
tag = fieldT.Name
|
tag = fieldT.Name
|
||||||
|
} else if tags[0] == "-" {
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
tag = tags[0]
|
tag = tags[0]
|
||||||
}
|
}
|
||||||
|
@ -104,8 +104,8 @@ func TestInSlice(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseForm(t *testing.T) {
|
func TestParseForm(t *testing.T) {
|
||||||
type user struct {
|
type user struct {
|
||||||
Id int
|
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
|
||||||
@ -114,6 +114,8 @@ func TestParseForm(t *testing.T) {
|
|||||||
|
|
||||||
u := user{}
|
u := user{}
|
||||||
form := url.Values{
|
form := url.Values{
|
||||||
|
"Id": []string{"1"},
|
||||||
|
"-": []string{"1"},
|
||||||
"tag": []string{"no"},
|
"tag": []string{"no"},
|
||||||
"username": []string{"test"},
|
"username": []string{"test"},
|
||||||
"age": []string{"40"},
|
"age": []string{"40"},
|
||||||
|
Loading…
Reference in New Issue
Block a user