This content originally appeared on DEV Community and was authored by Tomas Scott
If you’ve just switched to Go from PHP or Java, you’ve probably had this thought: Go’s standard library is awesome and has everything, but when it’s time to whip up a proper web app, it feels like you have to build everything from scratch. Routing, config, ORM… you’re burnt out before the project even begins.
Take it from someone who’s been there: that’s the wrong way to think. Seasoned Gophers have long learned to use the right tools for the job. Today, I’m opening up my go-to toolkit to share the 6 libraries that have become standard issue in almost every Go project.
Buckle up! Let’s roll.
Gin: The De Facto Standard for Web Development
Thinking of writing an API in Go? Don’t even think about it—nine out of ten projects use Gin. Why? One word: fast.
Gin’s routing performance is top-tier, and its API is incredibly intuitive. You can get an HTTP server up and running in just a few lines of code, letting you focus all your energy on business logic.
What makes it so great?
- Fast. Seriously fast: It uses
httprouter
under the hood, so performance is a non-issue. - Rich middleware ecosystem: Logging, auth, compression… just plug in whatever you need, like Lego bricks. Super handy.
- Dead simple: No fancy, complicated concepts. The learning curve is practically flat.
Check out the code:
package main
import "github.com/gin-gonic/gin"
func main() {
// Creates a router with default middleware (Logger and Recovery)
r := gin.Default()
r.GET("/hello", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "world"})
})
// Let's run it!
r.Run(":8080")
}
Ridiculously easy, right?
Viper: Tame Your Messy Configurations
As an application grows, its configuration becomes a mess: config.yaml
, environment variables, command-line flags… which one takes precedence? Viper is here to end the chaos.
What can it do for you?
- Handles any format: JSON, TOML, YAML, HCL, env files—it’s not picky.
- You set the priority: You can define the order of precedence, like: command-line flags > environment variables > config file.
- Live reloading: Change your config file, and Viper can automatically reload it without restarting your app. This is a godsend during development.
For example, reading a config.yaml
:
# config.yaml
server:
port: 8080
database:
user: "admin"
// main.go
import "github.com/spf13/viper"
// ... (some code omitted)
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.ReadInConfig()
port := viper.GetInt("server.port") // Easily gets 8080
user := viper.GetString("database.user") // Gets "admin"
GORM: Say Goodbye to Writing Raw SQL
If you’re still painstakingly writing raw SQL strings in your projects, you really need GORM to come to the rescue. It lets you interact with your database elegantly by manipulating Go structs.
Why does everyone love it?
- A joy to write: Its chainable API makes your code read like plain English.
- Powerful features: Associations, transactions, hooks—all these complex operations are handled for you.
- Auto Migration: Define your struct, and it will automatically create or update the database table for you. For small projects, this is a dream come true.
Get a feel for it:
import "gorm.io/gorm"
type User struct {
gorm.Model
Name string
Age int
}
// ... db connection ...
// Add a new user
db.Create(&User{Name: "Old Wang", Age: 30})
// Find Old Wang
var user User
db.First(&user, "name = ?", "Old Wang")
// user.Age is now 30
Way more pleasant than writing INSERT INTO...
and SELECT...
, isn’t it?
GoConvey: Makes Testing Less of a Chore
Let’s be honest, almost nobody genuinely loves writing tests. But GoConvey manages to make this chore… kind of fun.
Its killer feature is the web UI. As you change your code, it runs tests in real-time in your browser. Green bar or red bar, you get instant feedback.
Its highlights:
- Reads like a story: Its DSL (Domain-Specific Language) makes test logic incredibly clear.
- Live Web UI: This is the core feature. It’s a game-changer that will absolutely boost your motivation to write tests.
- Built-in coverage reports: See exactly what you’ve missed, crystal clear.
The test code looks like this:
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Add(a, b int) int { return a + b }
func TestAddition(t *testing.T) {
Convey("Given an addition function", t, func() {
So(Add(1, 2), ShouldEqual, 3)
So(Add(-1, 1), ShouldEqual, 0)
})
}
Just type goconvey
in your terminal, then sit back and watch the results in your browser.
Go Redis: The Only Redis Client You’ll Need
What modern backend project doesn’t rely on Redis? Caching, message queues, distributed locks… go-redis
is the top choice in the Go community for interacting with Redis. It’s stable and feature-complete.
Why choose it?
- Intuitive API: Its function names are nearly identical to native Redis commands, so there’s almost no learning curve.
- Reliable performance: With a built-in connection pool, it performs solidly under high concurrency.
- Has all the features: Pipeline, transactions, Pub/Sub, Sentinel, and Cluster mode are all supported.
Here’s a simple Set/Get:
import "github.com/go-redis/redis/v8"
// ... rdb client initialization ...
ctx := context.Background()
rdb.Set(ctx, "framework", "Gin", 0)
val, _ := rdb.Get(ctx, "framework").Result()
fmt.Println(val) // Outputs "Gin"
Logrus: For the Love of God, Stop Debugging with fmt.Println
!
Still littering your code with fmt.Println
for debugging? Friend, it’s time to level up. Logrus helps you output structured JSON logs, which is crucial for collecting and analyzing them later with tools like the ELK stack.
What makes Logrus awesome:
- Structured logging is a godsend: You can add fixed fields to every log entry (like a
request_id
), making filtering and searching a breeze when troubleshooting. - Log levels:
Info
,Warn
,Error
make the importance of each log entry immediately obvious. - Hooks: Easily send error logs to services like Slack, Sentry, or others for real-time alerting.
Look, you can log like this:
import log "github.com/sirupsen/logrus"
func main() {
log.SetFormatter(&log.JSONFormatter{})
log.WithFields(log.Fields{
"event": "login",
"user_id": 10086,
}).Info("User logged in successfully")
}
// The output will be a JSON object like this:
// {"event":"login","level":"info","msg":"User logged in successfully","time":"...", "user_id":10086}
Isn’t that way better than a screen full of plain strings?
First, You Gotta Set Up the Environment…
Alright, you’ve got the tools. But here’s the catch. To get this whole stack (Go + Gin + GORM + Redis + MySQL…) running locally, you have to:
- Install Go, configure
GOPATH
,GOPROXY
… Want to try a new version? Great, time to mess with everything again. - Install Nginx/Caddy and write a bunch of reverse proxy configs just to use a local domain.
- Install and manage MySQL, Redis, and PostgreSQL separately, and deal with port conflicts.
- Accidentally break your database? Forgot to back it up? Time to panic.
If every one of those points hit a nerve, then ServBay is your knight in shining armor (well, not literally).
Haven’t heard of ServBay for your dev environment? Let me give you the lowdown. ServBay is an integrated dev environment for web developers, currently supporting Windows and macOS. It’s a full-stack toolkit with a graphical interface that frees developers from tedious environment configuration.
How does it make your life easier?
-
Go Version Management? A Piece of Cake. Want to try out a new feature in Go 1.22 without messing up your old project that relies on Go 1.20? ServBay lets you switch between versions in a second, like changing TV channels. They won’t interfere with each other.
-
One-Click Local Tunnels? Got That Too. Still fiddling with ngrok? Need to show a client a demo or debug a webhook from a service like Stripe that requires a public URL? ServBay has a built-in tunneling feature. One click, and your local app gets a public domain you can share with anyone. Once you use it, you’ll wonder how you ever lived without it.
Reverse Proxy? Just Point and Click. No more studying Nginx’s
conf
syntax. In ServBay, enter your project’s address and desired domain, and it handles the rest automatically—even setting up HTTPS for you.One-Stop Service Center: It’s not just for Go. Python, Java, Node.js, MariaDB, PostgreSQL, Redis, MongoDB… all the common services are ready to go. Start or stop them with a single click. Clean and simple.
Automatic Database Backups: This feature is your get-out-of-jail-free card. ServBay can schedule automatic database backups for you. Accidentally
DROP
a database? Stay calm, restore from a backup, and get back to slacking off.
With ServBay, your daily routine becomes: Open laptop -> Open ServBay -> Start the services you need with a few clicks -> Open IDE -> Start coding happily.
All that annoying environment setup can go to hell.
Finally
A great tool doesn’t scream about how amazing it is; it just silently makes your work faster and more enjoyable.
The 6 Go libraries we talked about today are the wheels that make you “fly.” And ServBay is the personal pit crew that lets you focus on racing, without worrying about flat tires or refueling.
I hope this article helps. Spend your time creating, not fighting with your environment.
This content originally appeared on DEV Community and was authored by Tomas Scott