mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

How to handle key conflicts when using mapstructure:",squash" ?

Open dangquyitt opened this issue 8 months ago • 1 comments

type Order struct {
	Id string
}

type User struct {
	Id    string
	Order Order `mapstructure:",squash"`
}

result := map[string]interface{}{}
mapstructure.Decode(User{
	Id: "userId",
	Order: Order{
		Id: "orderId",
	},
}, &result)

log.Println(result)
Output: map[Id:orderId]
Expected: map[Id:userId Order.Id:orderId]

dangquyitt avatar Jun 13 '24 02:06 dangquyitt