Ayiga / go-kit-middlewarer

A utility for generating layers for the go-kit framework
MIT License
85 stars 9 forks source link

Generating for multiple interface in single file is really painful #6

Open kumaranvpl opened 8 years ago

kumaranvpl commented 8 years ago

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

kumaranvpl commented 8 years ago

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

Morgahl commented 8 years ago

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 commented 8 years ago

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.

kumaranvpl commented 8 years ago

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