Go keeps growing as a popular programming language and is now in 2024 a common choice for building cloud-native microservices applications. Go has even entered the Top 10 in the TIOBE programming languages index.
While Go historically does not have a strong culture of using frameworks, there are a few that have become established and these days developers should definitely consider them in order to boost productivity.
However, making the right choice can be challenging, so in this article we take a look at the leading frameworks and compare features, key use cases, and potential drawbacks.
Here's a high-level overview of the different frameworks included in this article, the frameworks are compared based on the level of built-on support for various use cases and functionality.
Encore | GoMicro | Go kit | Gin | |
---|---|---|---|---|
Description: | Backend Framework | Microservice Framework | Collection of Go libraries | Web Framework |
Use case: | Event-driven and Distributed Systems | Event-driven and Distributed Systems | Distributed systems | Performant HTTP APIs |
Transport protocols: | HTTP | HTTP, gRPC | HTTP, gRPC | HTTP |
Low boilerplate: | ✅︎ Yes | ✅︎ Yes | ✅︎ Yes | ✅︎ Yes |
Authentication: | ✅︎ Yes | ✅︎ Yes | ✅︎ Yes | ✅︎ Yes |
Service discovery: | ✅︎ Yes | ✅︎ Yes | ✅︎ Yes | ❌ No |
Async messaging: | ✅︎ Yes | ✅︎ Yes | ❌ No | ❌ No |
Built-in API Docs: | ✅︎ Yes | ✅︎ Yes | ❌ No | ❌ No |
Automatic Local Dev Infra: | ✅︎ Yes | ❌ No | ❌ No | ❌ No |
Built-in Tracing: | ✅︎ Yes | ❌ No | ❌ No | ❌ No |
Built-in Architecture Diagrams: | ✅︎ Yes | ❌ No | ❌ No | ❌ No |
Built-in Secrets Management: | ✅︎ Yes | ❌ No | ❌ No | ❌ No |
Built-in Preview Environments: | ✅︎ Yes | ❌ No | ❌ No | ❌ No |
Built-in Cloud Infra Automation: | ✅︎ Yes | ❌ No | ❌ No | ❌ No |
Built-in Cloud Cost Analytics: | ✅︎ Yes | ❌ No | ❌ No | ❌ No |
Encore.go is a modern alternative for building Go microservices, purposefully designed to make it less complex to build event-driven and distributed systems. Encore solves for both the local dev experience and assists with deployment using robust and scalable services from AWS and GCP. It works by providing a Backend Framework that lets you declare infrastructure semantics as part of the application code.
With Encore you define a service by defining an API within a regular Go package. Encore recognizes this as a service, and uses the package name as the service name. When deploying, Encore will automatically provision the required infrastructure for each service.
On disk it might look like this:
/my-app
├── encore.app // ... and other top-level project files
│
├── hello // hello service (a Go package)
│ ├── hello.go // hello service code
│ └── hello_test.go // tests for hello service
│
└── world // world service (a Go package)
└── world.go // world service code
This means building a microservices architecture is as simple as creating multiple Go packages within your application. See the app structure documentation for more details.
To define an API, add the //encore:api
annotation any regular Go function.
This tells Encore that the function is an API endpoint. Encore will then automatically generate the necessary boilerplate at compile-time.
In the example below, we define the API endpoint Ping
, in the hello
service, which gets exposed as hello.Ping
.
package hello // service name
//encore:api public
func Ping(ctx context.Context, params *PingParams) (*PingResponse, error) {
msg := fmt.Sprintf("Hello, %s!", params.Name)
return &PingResponse{Message: msg}, nil
}
If you want a Pub/Sub Topic, you declare it directly in your application code, like so:
import "encore.dev/pubsub"
type User struct { /* fields... */ }
var Signup = pubsub.NewTopic[*User]("signup", pubsub.TopicConfig{
DeliveryGuarantee: pubsub.AtLeastOnce,
})
// Publish messages by calling a method
Signup.Publish(ctx, &User{...})
To run your application, you simply use encore run
. Encore will automatically set up the local infrastructure and generate the boilerplate code necessary.
You also get a local development dashboard with distributed tracing to help you understand and debug application behavior with ease.
Your code doesn't change when you want to deploy to the cloud. Encore will generate the necessary boilerplate and provision the necessary infrastructure in all environments:
GoMicro (to be renamed Orb) is a microservice framework that aims to simplify the challenges of building scalable and maintainable applications. GoMicro provides a pluggable architecture that allows developers to select and adapt the framework to fit their requirements, and integrates with various service discovery systems.
Note: GoMicro has not had a new release since April 2023, so likely it should be approached with caution.
Go kit is a collection of Go packages (libraries) for building microservices in Go. It focuses on providing solutions to challenges commonly faced, while still remaining relatively unopinionated.
Gin is a performance-focused web framework for Go. Minimalistic in nature, Gin is appropriate for building small, focused, applications.
We hope this brief article helps inform your choice about which Go microservices framework to use in your project. Related to picking a framework, it's common to want to use an ORM to make it more efficient to use databases in your application. There are many ORMs to choose from, all with different characteristics. To help inform your decision, we've recently published a guide to the best Go ORMs.