katzien / go-structure-examples

Examples for my talk on structuring go apps
MIT License
2.34k stars 286 forks source link

Why are service interfaces not defined near the consumer (rest-handler)? #43

Open wilfreddesert opened 1 year ago

wilfreddesert commented 1 year ago

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!

godwhoa commented 1 year ago

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.

wilfreddesert commented 1 year ago

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.