我正在嘗試將 JSON 響應(yīng)模板化到前端,我當(dāng)前的結(jié)構(gòu)是這樣的: type Response struct { WhoisRecord struct { CreatedDate time.Time `json:"createdDate"` UpdatedDate time.Time `json:"updatedDate"` ExpiresDate time.Time `json:"expiresDate"` Registrant struct { Name string `json:"name"` Organization string `json:"organization"` Street1 string `json:"street1"` City string `json:"city"` State string `json:"state"` Country string `json:"country"` CountryCode string `json:"countryCode"` Email string `json:"email"` Telephone string `json:"telephone"` Fax string `json:"fax"` } `json:"registrant"` AdministrativeContact struct { Name string `json:"name"` Organization string `json:"organization"` Street1 string `json:"street1"` City string `json:"city"` State string `json:"state"` Country string `json:"country"` CountryCode string `json:"countryCode"` Email string `json:"email"` Telephone string `json:"telephone"` Fax string `json:"fax"` } `json:"administrativeContact"` TechnicalContact struct { Name string `json:"name"` Organization string `json:"organization"` Street1 string `json:"street1"` City string `json:"city"` State string `json:"state"`}然后我解組這個(gè) json 響應(yīng),并將它傳遞到前端(我正在使用 GIN)(響應(yīng)被重新聲明為res)c.HTML(200,"homework.html", gin.H{ "whois": res, })但這是我遇到問(wèn)題的地方,代碼可以工作,但我不確定如何模板化它,因?yàn)樗乔短椎?。例如,我想在單?dú)的表格中顯示注冊(cè)人、管理人員和技術(shù)聯(lián)系人的詳細(xì)信息(返回的所有字段)。以及顯示創(chuàng)建、更新和過(guò)期的日期。然后通過(guò)顯示注冊(cè)商、ips 和名稱服務(wù)器(在本例中為 下的hostnames字段NameServers)來(lái)完成但是這些都不起作用(我如何在一個(gè)字段中顯示注冊(cè)人姓名,然后在另一個(gè)字段中顯示技術(shù)名稱?我顯然把模板搞砸了,我對(duì)它的理解有點(diǎn)歪曲)。我已經(jīng)閱讀了我所能閱讀的所有內(nèi)容,我試圖劃分結(jié)構(gòu)并作為單獨(dú)的結(jié)構(gòu),等等。沒(méi)有任何工作。有人可以指出我正確的方向并舉例嗎?謝謝!
Golang如何模板化嵌套結(jié)構(gòu)?
夢(mèng)里花落0921
2022-06-21 10:58:36
