Go Tutorial #26: gRPC in Go — Building High-Performance APIs

In the previous tutorial, you built a complete microservice with REST. Now let’s learn gRPC — a faster alternative for service-to-service communication. gRPC is a high-performance RPC framework created by Google. It uses Protocol Buffers (protobuf) for serialization and HTTP/2 for transport. It is faster than REST+JSON, supports streaming, and generates client and server code automatically. When to Use gRPC vs REST Feature REST gRPC Format JSON (text) Protobuf (binary) Speed Good Faster (2-10x) Streaming Limited (WebSocket) Built-in Browser support Native Needs proxy Code generation Optional (OpenAPI) Built-in Human readable Yes No (binary) Use REST when: ...

April 14, 2026 · 9 min

Go Tutorial #25: Building a Microservice — Complete Project

In the previous tutorial, you learned Docker for Go. Now let’s put everything together and build a complete microservice. This is a project tutorial. You will build a notes API from scratch using the skills from the entire series: Gin for routing, PostgreSQL with sqlx for storage, JWT for authentication, validation for input, slog for logging, and Docker for deployment. What We Are Building A notes microservice with these endpoints: Method Path Description Auth POST /api/register Create account No POST /api/login Get JWT token No GET /api/notes List user’s notes Yes POST /api/notes Create a note Yes GET /api/notes/:id Get a note Yes PUT /api/notes/:id Update a note Yes DELETE /api/notes/:id Delete a note Yes GET /health Health check No Project Structure notes-api/ cmd/ server/ main.go # Entry point internal/ handler/ auth.go # Auth handlers (register, login) notes.go # Note CRUD handlers middleware.go # JWT middleware model/ user.go # User struct note.go # Note struct repository/ user.go # User database operations note.go # Note database operations service/ auth.go # Auth business logic go.mod go.sum Dockerfile docker-compose.yml This follows the clean architecture from Go Tutorial #10. ...

April 14, 2026 · 12 min

Go Tutorial #24: Docker for Go — Building Production Images

In the previous tutorial, you built a CLI tool with Cobra. Now let’s package your Go applications with Docker. Go and Docker are a perfect combination. Go compiles to a single static binary. No runtime, no dependencies, no virtual machine. You can run a Go binary in a Docker image that contains nothing else. The result? Production images under 15MB. A Simple Dockerfile Start with a basic Dockerfile for a Go web server: ...

April 13, 2026 · 7 min

Go Tutorial #23: Building CLI Tools with Cobra

In the previous tutorial, you learned about generics. Now let’s build something practical — a command-line tool. Go is one of the best languages for building CLI tools. It compiles to a single binary with no dependencies. Tools like Docker, kubectl, Hugo, and GitHub CLI are all written in Go using Cobra. In this tutorial, you will build a complete TODO CLI app. What is Cobra? Cobra is a library for creating CLI applications in Go. It provides: ...

April 13, 2026 · 9 min

Go Tutorial #22: Generics — Type Parameters in Go

In the previous tutorial, you learned API best practices. Now let’s explore one of Go’s most powerful features — generics. Before Go 1.18, you had two choices for writing reusable code: use interface{} (losing type safety) or write the same function for every type. Generics solve this problem. You write a function once, and it works with any type that meets your constraints. The Problem Without Generics Imagine you need a function to find the minimum value in a slice. Without generics, you write one function per type: ...

April 13, 2026 · 9 min

Go Tutorial #21: Input Validation and API Best Practices

In the previous tutorial, you learned how to read and write files in Go. Now let’s focus on making your APIs production-ready. Building an API that works is one thing. Building an API that is reliable, secure, and easy to use is another. In this tutorial, you will learn the best practices that separate hobby projects from production services. Input Validation with validator Manual validation gets messy fast. The go-playground/validator package lets you validate structs with tags: ...

April 13, 2026 · 8 min

Go Tutorial #20: File I/O — Reading and Writing Files

In the previous tutorial, you learned database access with sqlx. Now let us work with files. File I/O is one of the most common tasks in Go — reading configuration files, processing logs, exporting data, and more. Go makes file I/O simple with the os and bufio packages. And the io.Reader and io.Writer interfaces make everything composable. Reading an Entire File The simplest way to read a file is os.ReadFile: package main import ( "fmt" "log" "os" ) func main() { data, err := os.ReadFile("hello.txt") if err != nil { log.Fatal(err) } fmt.Println(string(data)) } os.ReadFile reads the entire file into memory as a byte slice. This is fine for small files. For large files, use a scanner or reader instead. ...

April 12, 2026 · 8 min

Go Tutorial #19: Database Access with sqlx

In the previous tutorial, you built JWT authentication for your API. But we stored users in memory — they disappear when the server restarts. It is time to use a real database. Go has a clean database interface in the standard library. And sqlx makes it even better by adding struct scanning and named queries. In this tutorial, you will learn how to use sqlx with PostgreSQL. database/sql — The Standard Interface Go’s database/sql package defines a standard interface for SQL databases. It works with any SQL database through drivers: ...

April 12, 2026 · 10 min

Go Tutorial #18: Middleware and JWT Authentication

In the previous tutorial, you learned how to test Go code. Now it is time to add authentication to your API. Middleware is the standard way to handle cross-cutting concerns like authentication, logging, and CORS. What is Middleware? Middleware is a function that runs before (or after) your handler. It sits between the request and the handler: Request → Middleware 1 → Middleware 2 → Handler → Response Common uses for middleware: ...

April 12, 2026 · 9 min

Go Tutorial #17: Testing in Go

In the previous tutorial, you built REST APIs with Gin. Now it is time to test your code. Go has a powerful testing framework built into the standard library — no external dependencies needed. Testing in Go is simple by design. Test files live next to the code they test, and you run them with one command: go test. Your First Test Create a file called math.go: package math func Add(a, b int) int { return a + b } func Divide(a, b int) (int, error) { if b == 0 { return 0, fmt.Errorf("cannot divide by zero") } return a / b, nil } Now create math_test.go in the same directory: ...

April 12, 2026 · 9 min