Open soqt opened 4 years ago
With a Service interface for each service you can create mocks to make testing easier wherever they are used(eg. handlers). You also get the benefit of being able to wrap your services with logging, tracing, metrics middleware.
With a Service interface for each service you can create mocks to make testing easier wherever they are used(eg. handlers). You also get the benefit of being able to wrap your services with logging, tracing, metrics middleware.
Thanks for your answer. That makes much sense!
Related to this: shouldn't the service constructors return the struct?
I guess it's due to service struct not being exported. But yeah "accept interfaces, return structs" is a common saying.
Hi Kat, after watching your talk, I found your project structure is very inspiring and I'm migrating my project to this structure now. I have a question. Why do you want to create a
Service
interface in every service package instead aService
struct? and all functions with(s *Service)
automatically bind to the struct. Is there any special use case forService
interface?