第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

初始化嵌套匿名結(jié)構(gòu)

初始化嵌套匿名結(jié)構(gòu)

Go
料青山看我應(yīng)如是 2022-04-20 20:46:53
我想用 func 處理結(jié)構(gòu)內(nèi)部的結(jié)構(gòu):我的代碼:package modelstype CalendarPushNotification struct {    Id                  string      `db:"id"`    UserId              string      `db:"user_id"`    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 {    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"`    }`json:"schedules"`}var CalendarUtils = CalendarPushNotification{}func (CalendarPushNotification) GetResponseGetCalendar(model *CalendarPushNotification) * ResponseGetCalendar {    return &ResponseGetCalendar{            EventId:            model.EventId,            Title:              model.Title,            StartDate:          model.StartDate,            PushDate:           model.PushDate,            PushDeliveryLineId: model.PushDeliveryLineId,            IsPushDelivered:    model.IsPushDelivered,    }}返回 struct 時(shí),我的 funcGetResponseGetCalendar看不到 struct 中的成員。ResponseGetCalendar struct我錯(cuò)過(guò)了什么?
查看完整描述

3 回答

?
慕標(biāo)5832272

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊

如果您將 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,

        },

    }

}


查看完整回答
反對(duì) 回復(fù) 2022-04-20
?
ITMISS

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊

View是一個(gè)匿名結(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


查看完整回答
反對(duì) 回復(fù) 2022-04-20
?
BIG陽(yáng)

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

錯(cuò)誤是因?yàn)?ResponseGetCalendar 結(jié)構(gòu)中缺少結(jié)構(gòu)視圖。將您的替換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

}


查看完整回答
反對(duì) 回復(fù) 2022-04-20
  • 3 回答
  • 0 關(guān)注
  • 127 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)