Skip to content

struct flat #54

@haodiao

Description

@haodiao
var structA struct {
	ID int `json:"id" msgpack:"id"`
}
var structB []struct {
	structA
	Title string `json:"title" msgpack:"title"`
}

for _, s := range structAarrs {
    item := struct {
        structA
        Title string `json:"title" msgpack:"title"`
    }{
        Title: Title,
    }
    
    item.structA= s
    structB = append(structB, item)
}

expect:

[
  {
     "id": 1,
     "title": "title"
  }
]

actual:

[
  {
      "structA": {
          "id": 1
      },
      "title": "title"
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions