3 回答

TA貢獻1829條經(jīng)驗 獲得超13個贊
如果您將 View 設(shè)置為非匿名結(jié)構(gòu),您可以執(zhí)行以下操作:
type View struct {
EventId string `db:"event_id"`
Title string `db:"title"`
StartDate string `db:"start_date"`
PushDate string `db:"push_date"`
PushDeliveryLineId string `db:"push_delivery_line_id"`
IsPushDelivered string `db:"is_push_delivered"`
}
type ResponseGetCalendar struct {
Schedules View `json:"schedules"`
}
var CalendarUtils = CalendarPushNotification{}
func (CalendarPushNotification) GetResponseGetCalendar(model *CalendarPushNotification) *ResponseGetCalendar {
return &ResponseGetCalendar{
Schedules: View{
EventId: model.EventId,
Title: model.Title,
StartDate: model.StartDate,
PushDate: model.PushDate,
PushDeliveryLineId: model.PushDeliveryLineId,
IsPushDelivered: model.IsPushDelivered,
},
}
}

TA貢獻1850條經(jīng)驗 獲得超11個贊
View是一個匿名結(jié)構(gòu)。初始化匿名結(jié)構(gòu)可能很乏味。你必須做:
&ResponseGetCalendar{
View: struct { // List all elements of View here}
{ // List them again and initialize them here}
}
相反,你可以這樣做:
ret:= &ResponseGetCalendar{}
ret.View.EventId=model.EventId
...
return ret

TA貢獻1719條經(jīng)驗 獲得超6個贊
錯誤是因為 ResponseGetCalendar 結(jié)構(gòu)中缺少結(jié)構(gòu) View。將您的替換GetResponseGetCalendar func為以下內(nèi)容:
func (CalendarPushNotification) GetResponseGetCalendar(model *CalendarPushNotification) *ResponseGetCalendar {
ret := &ResponseGetCalendar{}
ret.View.EventId = model.EventId
ret.View.Title = model.Title
ret.View.StartDate = model.StartDate
ret.View.PushDate = model.PushDate
ret.View.PushDeliveryLineId = model.PushDeliveryLineId
ret.View.IsPushDelivered = model.IsPushDelivered
return ret
}
- 3 回答
- 0 關(guān)注
- 195 瀏覽
添加回答
舉報