What is (t *SimpleAsset) in this function

235 Views Asked by At
func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response  

I have been trying to understand hyperledger in which we use Go language for Chaincode. But here I am unable to understand what the (t* SimpleAsset) is. I do understand that unit is the name of the function, stub part is the argument and peer.Response is the return type. As I am new to Go please help me thank you.

1

There are 1 best solutions below

0
On BEST ANSWER

In the following code:

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

(t *SimpleAsset) is the receiver. Go, unlike many other languages allows you to add methods to any (user defined) type (including functions!), and the type you are adding the method to is refered to here.

Notice that the author of this code names his receiver t instead of something like self or this? In Go there is no special rule for naming a receiver, you just name it like you would a parameter.

Go by example has a nice clear explanation of the basics, but the Go specification is also very helpful.