2017-08-27 168 views
0
func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response 

我一直在試圖理解hyperledger中,我們使用Go語言Chaincode。但在這裏我無法理解(t* SimpleAsset)是什麼。 我也明白,單位是函數的名稱,存根部分是論證和peer.Response是返回類型。由於我是Go的新手,請幫助我,謝謝。什麼是(T * SimpleAsset)在這個函數

+0

'(T * SimpleAsset)'說,這是一個方法,'SimpleAsset'結構 – Malice

+0

這是否意味着在走結構都像類或別的什麼方法呢? –

+2

這應該清除一切:-)。 https://gobyexample.com/methods – Malice

回答

2

在以下代碼:

func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response 

(t *SimpleAsset)接收機。走,不像許多其他語言可以讓你的方法添加到任何(用戶定義)類型(包括功能!),類型要添加的方法是refered到這裏。

注意到,此代碼名稱他的接收器t,而不是像selfthis的作者?在Go中,沒有特別的規則來命名接收器,您只需將它命名爲參數即可。

Go by example對基礎知識有很好的清晰解釋,但the Go specification也很有幫助。

相關問題