0
如何將struct的字段類型定義爲struct?轉到 - 如何將struct字段的數據類型定義爲另一個struct
我希望能有類似如下:
type HelloResp struct {
Response struct `xml:resp`
}
func (hr *HelloResp) SetHelloResp(interf interface{}) {
hr.Response = interf
}
基本上我有幾個其他孩子的結構我想嵌入HelloResp.Response
下根據需要使它們的功能互換。
這是否可以或有推薦的Go方式嗎?
我不想使用unmarshall,因爲它使用了反射,而且對性能不好。我將不得不嘗試使用指針並動態指向結構級別 – 2014-10-11 11:04:09
您已經在使用unmarshall。第一種方法只是延遲嵌入式結構的處理。 – 2014-10-11 12:17:15
你是否介紹了你的應用程序?解除瓶頸? – RickyA 2014-10-13 13:32:17