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

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

從返回元組的 func 初始化結(jié)構(gòu)

從返回元組的 func 初始化結(jié)構(gòu)

Go
繁花如伊 2023-05-22 16:07:20
好的,我有這個(gè):handler.Mount(subRouter, routes.PersonInjection{PeopleById: models.PersonInit()})PersonInit 看起來(lái)像:func PersonInit() (Map,Map) {    peopleById["1"] = Model{ID: 1, Handle: "alex", Firstname: "Alex", Lastname: "Chaz", Email: "alex@example.com", Password:"foo"}    peopleById["2"] = Model{ID: 2, Handle: "jason",Firstname: "Jason", Lastname: "Statham", Email: "jason@example.com", Password:"foo"}    peopleByHandle["alex"] = peopleById["1"]    peopleByHandle["jason"] = peopleById["2"]    return peopleById, peopleByHandle}地圖類型只是Map[string]someStruct{}看起來(lái)PersonInjection{}像:type PersonInjection struct {    PeopleById, PeopleByHandle person.Map}所以我想做類似的事情:handler.Mount(subRouter, routes.PersonInjection{PeopleById,PersonByHandle: models.PersonInit()...})嗯,有人知道怎么做嗎?現(xiàn)在我只有:    by_id, by_handle := models.PersonInit()    handler.Mount(subRouter, routes.PersonInjection{PeopleById: by_id, PeopleByHandle:by_handle})
查看完整描述

1 回答

?
開滿天機(jī)

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

Go 中沒(méi)有結(jié)構(gòu)可以幫助制作這個(gè)單行代碼。我認(rèn)為,除了變量名中的下劃線,你現(xiàn)在擁有的是好的。

就個(gè)人而言,為了可讀性,我會(huì)添加更多行:

var?personInj?routes.PersonInjection
personInj.PeopleById,?personInj.PeopleByHandle?=?models.PersonInit()
handler.Mount(subRouter,?personInj)


查看完整回答
反對(duì) 回復(fù) 2023-05-22
  • 1 回答
  • 0 關(guān)注
  • 170 瀏覽
慕課專欄
更多

添加回答

舉報(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)