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.
In the following code:
(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 likeself
orthis
? 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.