什么是(T * SimpleAsset)在这个函数
问题描述:
func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response
我一直在试图理解hyperledger
中,我们使用Go
语言Chaincode
。但在这里我无法理解(t* SimpleAsset)
是什么。 我也明白,单位是函数的名称,存根部分是论证和peer.Response
是返回类型。由于我是Go
的新手,请帮助我,谢谢。什么是(T * SimpleAsset)在这个函数
答
在以下代码:
func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response
(t *SimpleAsset)
是接收机。走,不像许多其他语言可以让你的方法添加到任何(用户定义)类型(包括功能!),类型要添加的方法是refered到这里。
注意到,此代码名称他的接收器t
,而不是像self
或this
的作者?在Go中,没有特别的规则来命名接收器,您只需将它命名为参数即可。
Go by example对基础知识有很好的清晰解释,但the Go specification也很有帮助。
'(T * SimpleAsset)'说,这是一个方法,'SimpleAsset'结构 – Malice
这是否意味着在走结构都像类或别的什么方法呢? –
这应该清除一切:-)。 https://gobyexample.com/methods – Malice