Golang interface implementations?

Written by
reddit
Link to Post

https://www.reddit.com/r/golang/comments/bog1np/golang_interface_implementations/ by 

Hello, I’m writing a package for service discovery. That package will support multiple service discovery packages out there.

So I defined an interface for the package // Client exposes API for this package type Client interface { Register(tags []string) error Deregister() error Service(service, tag string) ([]*api.ServiceEntry, *api.QueryMeta, error) } Initially I was thinking for Consul, so I’ve defined the Service interface function like this: Service(service, tag string) ([]*api.ServiceEntry, *api.QueryMeta, error) You can see this in the interface definition. It just returns a list of ServiceEntry, a QueryMeta and error. These are specific to consul.

Then I faced the real problem, when I try to implement the interface with other things, like etcd. as Service function returns something that is coupled to only consul, so I can not implement that function with other things.

Now I am thinking about other solutions. In general term, the sole purpose of the Service function would be to return a list of ip-addresses and ports for the specific service that the client will look for. What will be the correct approach for defining package API with interfaces? Thanks.

submitted by /u/CrappyFap69
[link] [comments]

Article Tags:
· ·
Article Categories:
reddit

Leave a Reply