Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created September 23, 2021 03:04
Show Gist options
  • Save xeoncross/01fc916f7b93f50cf5eb3b1c07501a9f to your computer and use it in GitHub Desktop.
Save xeoncross/01fc916f7b93f50cf5eb3b1c07501a9f to your computer and use it in GitHub Desktop.
What are the best choices for minimizing the amount of boilerplate required to get a service online?

I'm looking at OpenAPI generation and I see three main forms:

Service + Design

I really like the look of go-restful when it comes to adding hundreds of api endpoints. You define your service (actual business logic) and you define your routes with request/response structs and you're done. Validation, decoding/encoding, swagger docs, etc... is all taken care of - but you can only use HTTP. https://github.com/emicklei/go-restful-openapi/blob/dec9f41f12/examples/user-resource.go

Service + Design + Boilerplate

Next you have go-kit which requires additional definitions for decoding, but also allows you to define different transports (HTTP, gRPC, cli, and even NATS!) still, for rest-only servers seems like overkill to have to write all that boilerplate code for each service method. https://github.com/go-kit/examples/blob/master/stringsvc4/main.go#L153-L205

Service + Design + Code Generation

Last we have goa which is similar to go-restful in which you write your service and design spec (for rest, grpc, etc..) but different in that you use code generation to write all the implementations (only http and grpc supported?) and encoding/decoding logic for request/response types. https://github.com/goadesign/examples/blob/175371c1d3/basic/calc.go

(What is interesting is that goa can actually use gokit: https://github.com/goadesign/plugins/blob/v3/goakit/README.md)

So are there any other choices here? I'd like to stick with sqlc for model generation based on written SQL queries and limit the amount of typing and wrangling I have to do when plugging a service + store interface into an actual webserver/cli/queue/grpc instance so the outside world can interact with it.

@xeoncross
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment