2017-08-27 166 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也很有帮助。

相关问题