这个函数中的(t * SimpleAsset)是什么

时间:2017-08-27 12:17:46

标签: go hyperledger-fabric

duration_events

我一直在努力了解func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response hyperledger我们使用Go语言Chaincode。但在这里我无法理解(t* SimpleAsset)是什么。 我理解unit是函数的名称,stub部分是参数,peer.Response是返回类型。因为我是Go的新手,请帮助我,谢谢你。

1 个答案:

答案 0 :(得分:2)

在以下代码中:

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

(t *SimpleAsset)接收器。 Go,与许多其他语言不同,允许您向任何(用户定义)类型(包括函数!)添加方法,并且此处提到了要添加方法的类型。

请注意,此代码的作者将其接收者命名为t而不是selfthis?在Go中,没有用于命名接收器的特殊规则,您只需将其命名为参数。

Go by example对基础知识有一个很好的清晰解释,但the Go specification也非常有帮助。