3 回答
TA贡献1966条经验 获得超4个赞
如果您将 View 设为非匿名结构,则可以执行以下操作:
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贡献1871条经验 获得超8个赞
View是一个匿名结构。初始化匿名结构可能很乏味。你所要做的:
&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贡献1859条经验 获得超6个赞
错误是因为 ResponseGetCalendar 结构中缺少结构视图。将您的替换GetResponseGetCalendar func为以下内容:
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 关注
- 103 浏览
添加回答
举报