go-kit / kit

A standard library for microservices.
https://gokit.io
MIT License
26.54k stars 2.43k forks source link

Service generator #631

Closed vetcher closed 4 years ago

vetcher commented 6 years ago

Hi, could you look at small tool for generate microservices and write your thoughts about it?

anarcher commented 6 years ago

WOW! IMHO, the generator is very good. @peterbourgon What do you think about it? :-)

peterbourgon commented 6 years ago

Looks cool! Can you maybe commit the output of running microgen on the example svc? It would make it easier to see what you get :)

vetcher commented 6 years ago

You may check output here. @peterbourgon

Raffo commented 6 years ago

@Vetcher I checked it and it looks cool, I like the idea. I found a couple of issues and I opened the relative GH issues to track them. It would be cool to understand the workflow around this tool, what we can edit, what we can customize, how do you think we should work with it.

vetcher commented 6 years ago

@Raffo In @devimteam projects we use microgen in 3 cases:

  1. Creating new service.
  2. Update service API.
  3. Change logging.

In this way, the workflow looks like:

At this moment, microgen not supports customization, except logging middleware and @grpc-addr and @protobuf tags, which are really can't be named Customization. In my humble opinion, microgen should provide best-practice code as many as it can without editing, so enhancements to code style or any ideas are welcome.

The answer to your question what we can edit in generated code is what you want. Microgen tries to describe future behavior in file comments.

Correct me if I understand your questions wrong.

Raffo commented 6 years ago

My question was mostly regarding subsequent generation after the first one, plugging custom middlewares in the main and so on. If I understand correctly, the suggestion is that we keep the interface and structs of the main business logic together in the same file and then generate all the boilerplate with microgen service.go.

Another thing that I see we should customize are http response codes and I am not sure how they are handled in microgen (haven't checked yet).

vetcher commented 6 years ago

Microgen does not overwrites main.go if it exist, so you may change it as you want. Behavior is different for each tag(file), I tried to describe it in tags section.

Struct, which implements interface, and it's methods are just an entry point to business logic. Also, in most common cases, you don't want to create 2 or more implementations of your API, so keep interface and it's single implementation together is good idea, imho.

GrantZheng commented 4 years ago

Hi, the Go-kit and Gokit-Cli are both great jobs, they are widely used in our team. And I have updated Gokit-CLi for go module support and continue to maintain it with the go-kit and golang features in the future. https://github.com/GrantZheng/kit/releases/tag/v1.0.0