This repository is an example (and barebones) implementation of the Service Framework we use at Conversion for service-to-service communication. Specifically, this style of framework allows services to call each other with strong types all defined in Golang (omitting the need of outside tools like protobuf / gRPC).
In comparison with frameworks like huma and fuego this framework does not include tooling for OpenAPI spec generation and instead uses generics to handle calls across services. This is important as without strong build tools like Bazel, intermediate steps like compiling to OpenAPI then generating handlers takes an unexpectedly large amount of time.
A core and stripped down version of how we implement the service framework is available in the serviceframework package. We use the power of generics to ensure that Endpoint
structs are strongly typed. Additionally, with the strongly typed Endpoint
we can now use this in conjunction with a defined handler
and form the complete request.
This simple idea allows us to build a completely Golang native service-to-service communication framework. Additionally, we are able to add additional middleware which is called at the handler / endpoint level. This gives us the capability to add common shared infrastructure components like metrics, logging, and security middleware.
In order to use the Service Framework, we need to define the endpoints and their schemas. Once this is done, other services just need to create a handler for the other services and can now freely call the other endpoint with strong types.
This sample repo can be run by simply calling go run .
in both of the services/auth
and services/email
to run the servers at the same time. Finally, we can call the example endpoint in email
which will perform a strongly typed call to auth
.
❯ curl -X POST http://localhost:3000/send-email \
-H "Content-Type: application/json" \
-d '{
"recipient": "test@example.com",
"subject": "Test Email"
}'
{"success":true}