duration_events
我一直在努力了解func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response
hyperledger
我们使用Go
语言Chaincode
。但在这里我无法理解(t* SimpleAsset)
是什么。
我理解unit是函数的名称,stub部分是参数,peer.Response
是返回类型。因为我是Go
的新手,请帮助我,谢谢你。
答案 0 :(得分:2)
在以下代码中:
func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response
(t *SimpleAsset)
是接收器。 Go,与许多其他语言不同,允许您向任何(用户定义)类型(包括函数!)添加方法,并且此处提到了要添加方法的类型。
请注意,此代码的作者将其接收者命名为t
而不是self
或this
?在Go中,没有用于命名接收器的特殊规则,您只需将其命名为参数。
Go by example对基础知识有一个很好的清晰解释,但the Go specification也非常有帮助。