go-kit-middlewarer icon indicating copy to clipboard operation
go-kit-middlewarer copied to clipboard

Generating for multiple interface in single file is really painful

Open kumaranvpl opened this issue 8 years ago • 4 comments

I am manually cleaning up the generated code for multiple interfaces.

kumaranvpl avatar Jul 07 '16 11:07 kumaranvpl

Please write example in go-kit-middelwarer for following go-kit example https://github.com/go-kit/kit/tree/master/examples/shipping/booking

kumaranvpl avatar Jul 07 '16 13:07 kumaranvpl

It is generally assumed in this package, and may need to be made more clear in the future, that a single interface for your microservice is expected.

Multiple interfaces tends to indicate a bifurcation of business logic and MAY need refactoring. More often then not, in this situation, this actually means that you should be separating out each of these interfaces into separate microservices entirely as the service is trying to do too many things at once.

As shown in the below layout from the read me, go-kit-middlewarer currently expects you to follow the below structure:

+-- endpoint
|   +-- defs_gen.go
+-- logging
|   +-- middleware_gen.go
+-- transport
|   +-- http
|   |    +-- client_gen.go
|   |    +-- http-client-loadbalanced_gen.go
|   |    +-- http-client_gen.go
|   |    +-- http-server_gen.go
|   |    +-- make-endpoint_gen.go
|   |    +-- request-response_gen.go
+-- <service>.go

This expects a single interface in the <service>.go file to define your microservice's interface. For myself I tend to further extend this theme with a logic folder as below:

+-- endpoint
|   +-- defs_gen.go
+-- logging
|   +-- middleware_gen.go
+-- logic
|   +-- <...>
|   +-- implementation.go
+-- transport
|   +-- http
|   |    +-- client_gen.go
|   |    +-- http-client-loadbalanced_gen.go
|   |    +-- http-client_gen.go
|   |    +-- http-server_gen.go
|   |    +-- make-endpoint_gen.go
|   |    +-- request-response_gen.go
+-- <service>.go

In this example, <service>.go contains the interface for the microservice that gokit generates code for and implementation.go contains the code that actually conforms to said interface defined in <service>.go

I'll spend a bit of time today to refactor the shipping example from https://github.com/go-kit/kit/tree/master/examples/shipping into a go-kit-middlewarer built collection of microservices to give you an example to base multiple services off of.

Morgahl avatar Jul 07 '16 16:07 Morgahl

This might take a bit longer then I had previously expected. I've been digging into the shipping example and it appears this is exactly the situation I'd expect separate microservices to exist instead of a complicated multi-interface setup that currently exists.

Morgahl avatar Jul 07 '16 18:07 Morgahl

@curlymon Thanks for your effort in converting that shipping example. Let me know after converting it.

kumaranvpl avatar Jul 08 '16 06:07 kumaranvpl