Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kumaranvpl opened this issue Jul 7, 2016 · 4 comments
Open

Comments

@kumaranvpl
Copy link

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

@kumaranvpl
Copy link
Author

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

@Morgahl
Copy link
Contributor

Morgahl commented Jul 7, 2016

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
Copy link
Contributor

Morgahl commented Jul 7, 2016

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants