msgpack icon indicating copy to clipboard operation
msgpack copied to clipboard

struct flat

Open haodiao opened this issue 3 months ago • 0 comments

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"
  }
]

haodiao avatar Nov 07 '25 06:11 haodiao