type Order struct {
*Res
Status int
}
type Res struct {
ResID int64
OtaBookID string
StayDetail []*ResElement
TotalCharge float64
CustFName string
CustLName string
CreateTime time.Time
}
type ResElement struct {
Res *Res
OtaEleID string
OtaRoomID string
RoomID int
Arrival time.Time
Depart time.Time
Charge float64
CreateTime time.Time
}
I have a slice named orderList to record orders. Now i have the first order which OtaBookID is "A123", and i want to copy this order and change its OtaBookID to "B123". The ResElement type have some other detail info to record this order and i hide them because it not affect my question. I can success change Res.OtaBookID but i have no idea how to change Res.StayDetail[0].Res.OtaBookID
func main() {
var orderList []*Order
res := new(Res)
res.OtaBookID = "A123"
resElt := new(ResElement)
resElt.Res = res
res.StayDetail = append(res.StayDetail, resElt)
order := new(Order)
order.Res = res
orderList = append(orderList, order)
originalOrder := new(Order)
originalOrder.Res = new(Res)
*originalOrder.Res = *order.Res
//originalOrder.Res.StayDetail[0].Res.OtaBookID = "B123" //this will make all become "B123"
originalOrder.Res.OtaBookID = "B123"
orderList = append(orderList, originalOrder)
fmt.Println(orderList[0].Res.OtaBookID) //A123
fmt.Println(orderList[1].Res.OtaBookID) //B123
fmt.Println(orderList[0].Res.StayDetail[0].Res.OtaBookID) //A123
fmt.Println(orderList[1].Res.StayDetail[0].Res.OtaBookID) //A123, i want this become B123
}
The result i want is orderList[0].Res.OtaBookID and orderList[0].Res.StayDetail[0].Res.OtaBookID is "A123" and other is "B123"
ps: Because i'm taking over other's works. So the three type already fixed and can not adjust. I want to know in this situation whether have any method to arrive my goal