Home > front end >  how to see method's receiver when there are double
how to see method's receiver when there are double

Time:01-27

I am trying to understand this example. Is Ccc method of aaa OR bbb or aaa.bbb().

When I go to github, and click on Ccc, I see bunch of Definitions and it's very inconvenience not knowing where to look.

ans := aaa.Bbb().Ccc()

Real example https://github.com/CyCoreSystems/ari/blob/master/_examples/play/main.go

sub := cl.Bus().Subscribe(nil, "StasisStart")

CodePudding user response:

Real example https://github.com/CyCoreSystems/ari/blob/master/_examples/play/main.go sub := cl.Bus().Subscribe(nil, "StasisStart")

In this example

cl is Client struct that implementing Client interface that has Bus() method.

Bus method signiture under Client interface is: Bus() Bus

Therefore cl.Bus() return some implementation of Bus interface.

Bus interface is encapsulate Subscriber interface that has the following method:

Subscribe(key *Key, n ...string) Subscription

That's why you can access to Subscribe(..) method if you have Bus interface in your hands

I hope I helped to understand the "real example"

CodePudding user response:

I am trying to understand this example. Is Ccc method of aaa OR bbb or aaa.bbb().

Ccc() is a method of whatever type Bbb() returns. This code:

ans := aaa.Bbb().Ccc()

Is the same as this code:

temp := aaa.Bbb()
ans := temp.Ccc()
  •  Tags:  
  • Related