I have this data model
type ResponseQueryHotel struct {
QueryString *string `json:"queryString"`
Status string `json:"status"`
Action string `json:"action"`
RefCode string `json:"refCode"`
Vendorid string `json:"vendorid"`
SearchToken *string `json:"searchtoken"`
Data struct {
Hotels []struct {
Data ResponseQueryHotelsData `json:"data"`
} `json:"hotels"`
} `json:"data"`
}
type ResponseQueryHotelsData struct {
Hotelidvendor string `json:"hotelidvendor"`
Hotelname string `json:"hotelname"`
Hoteladdress string `json:"hoteladdress"`
Hoteldistrict string `json:"hoteldistrict"`
Hotelcity string `json:"hotelcity"`
Hotelprovince string `json:"hotelprovince"`
Hotelcountry string `json:"hotelcountry"`
Hotellat string `json:"hotellat"`
Hotellng string `json:"hotellng"`
Hotelprice string `json:"hotelprice"`
Hoteldiscountprice string `json:"hoteldiscountprice"`
Hotelphotourl string `json:"hotelphotourl"`
}
now i need to insert the ResponseQueryHotelsData to ResponseQueryHotel.Data.Hotels right, so i try this
var output models.ResponseQueryHotel
var data models.ResponseQueryHotelsData
output.Data.Hotels = append(output.Data.Hotels, data)
but i get this error
cannot use data (variable of type models.ResponseQueryHotelsData) as struct{Data models.ResponseQueryHotelsData "json:\"data\""} value in argument to append
what should i do to a append the Data to output.Data.Hotels (there will be more than 1 ‘ResponseQueryHotelsData’ that will be inserted)
and btw i can’t change the data (it’s not up to me)
>Solution :
output.Data.Hotels = append(output.Data.Hotels, struct {
Data ResponseQueryHotelsData `json:"data"`
}{Data: data})