forked from Mirrors/jsonapi
Merge pull request #2 from shwoodard/fix-panic-on-no-tag
paniced before when added Blog field to Post
This commit is contained in:
commit
079f9c91ec
10
request.go
10
request.go
|
@ -77,13 +77,17 @@ func unmarshalNode(data *Node, model reflect.Value, included *map[string]*Node)
|
|||
return false
|
||||
}
|
||||
|
||||
fieldValue := modelValue.Field(i)
|
||||
fieldType := modelType.Field(i)
|
||||
tag := fieldType.Tag.Get("jsonapi")
|
||||
if tag == "" {
|
||||
i += 1
|
||||
return false
|
||||
}
|
||||
|
||||
fieldValue := modelValue.Field(i)
|
||||
|
||||
i += 1
|
||||
|
||||
tag := fieldType.Tag.Get("jsonapi")
|
||||
|
||||
args := strings.Split(tag, ",")
|
||||
|
||||
if len(args) != 2 {
|
||||
|
|
20
response.go
20
response.go
|
@ -123,17 +123,21 @@ func visitModelNode(model interface{}, sideload bool) (*Node, []*Node, error) {
|
|||
|
||||
var i = 0
|
||||
modelType.FieldByNameFunc(func(name string) bool {
|
||||
fieldValue := modelValue.Field(i)
|
||||
structField := modelType.Field(i)
|
||||
|
||||
i += 1
|
||||
|
||||
tag := structField.Tag.Get("jsonapi")
|
||||
|
||||
if tag == "" {
|
||||
if er != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
structField := modelType.Field(i)
|
||||
tag := structField.Tag.Get("jsonapi")
|
||||
if tag == "" {
|
||||
i += 1
|
||||
return false
|
||||
}
|
||||
|
||||
fieldValue := modelValue.Field(i)
|
||||
|
||||
i += 1
|
||||
|
||||
args := strings.Split(tag, ",")
|
||||
|
||||
if len(args) != 2 {
|
||||
|
|
|
@ -19,6 +19,7 @@ type Blog struct {
|
|||
}
|
||||
|
||||
type Post struct {
|
||||
Blog
|
||||
Id int `jsonapi:"primary,posts"`
|
||||
BlogId int `jsonapi:"attr,blog_id"`
|
||||
Title string `jsonapi:"attr,title"`
|
||||
|
|
Loading…
Reference in New Issue