go-structure-examples
go-structure-examples copied to clipboard
Why are service interfaces not defined near the consumer (rest-handler)?
Hi! I am referring to the hexagonal architecture example. It's a well-known idiom in Go that a consumer defines the interfaces it needs. In this particular case, why not define the three service interfaces in the http package?
Thanks!
I guess defining the interface in a more central place makes sense if you anticipate more than one consumer. Like say supporting two transports HTTP & gRPC.
Thanks for answering. I don't really understand what it simplifies though. If I understand correctly, the idea is to avoid copying the same interface in all so-called "driver adapters". But a little copying never killed nobody, quoting the Go proverbs.
Also, I'm not sure what is the benefit of returning the Service interface instead of a concrete implementation struct.