Go Cookbook

A collection of practical Go code snippets and recipes for common programming tasks.

Go Capabilities

Powerful solutions for modern application development

Parse JSON

Efficiently decode and encode JSON data with Go's standard library

Learn more

main.go

All Categories

Browse all available categories of Go snippets to find solutions quickly

Basics

Learn fundamental Go concepts, syntax, and idiomatic patterns for beginners

View Snippets

Builds And Compilations

Master build tools, cross-compilation, and deployment techniques

View Snippets

CLI Tools

Create powerful command-line applications with flags, input handling, and more

View Snippets

Code Generation

Automate code creation with templates, AST processing, and reflection

View Snippets

Collections

Work with slices, maps, and custom data structures efficiently

View Snippets

Concurrency

Leverage goroutines, channels, and sync primitives for parallel processing

View Snippets

Context

Manage deadlines, cancellation, and request-scoped values in your applications

View Snippets

Cryptography

Implement secure hashing, encryption, and digital signatures

View Snippets

Databases

Connect to SQL/NoSQL databases with efficient patterns and migrations

View Snippets

Debugging

Explore Go code snippets related to debugging

View Snippets

Distributed Systems

Build resilient microservices, service discovery, and load balancing

View Snippets

Error Handling

Implement robust error handling patterns and custom error types

View Snippets

Files

Work with file I/O, paths, and filesystem operations

View Snippets

Generics

Use type parameters for flexible, type-safe code since Go 1.18

View Snippets

HTTP

Create performant web servers, REST APIs, and HTTP clients

View Snippets

Language Idioms

Use idiomatic patterns for common programming tasks

View Snippets

Localization

Build multi-language applications with translations and formatting

View Snippets

Logging

Implement structured logging, rotation, and integration with monitoring

View Snippets

Memory Management

Optimize memory usage, garbage collection, and avoid leaks

View Snippets

Modules

Manage dependencies with Go modules and versioning

View Snippets

Networking

Work with TCP/UDP sockets, DNS, and low-level network protocols

View Snippets

Other Topics

Explore the other topics related to Go development

View Snippets

Patterns

Learn design patterns and best practices for Go programming

View Snippets

Performance Optimizations

Optimize your Go applications for better performance

View Snippets

Project Structure

Organize your Go projects with best practices

View Snippets

RPC

Implement Remote Procedure Calls with gRPC and other protocols

View Snippets

Runtime

Explore the runtime system, garbage collection, and memory management

View Snippets

Security

Secure your applications against common vulnerabilities

View Snippets

Serialization

Convert data between different formats like JSON, XML, and Protocol Buffers

View Snippets

Standard Library Packages

Explore the standard library packages and their use cases

View Snippets

Strings

Efficiently manipulate text with string operations and formatting

View Snippets

System Programming

Interface with the operating system for advanced operations

View Snippets

Templates

Generate dynamic content with Go's powerful templating engine

View Snippets

Testing

Write unit tests, benchmarks, and use mocking effectively

View Snippets

Time

Handle dates, durations, and time-based operations

View Snippets

Tools

Discover utility functions and helpers for common programming tasks

View Snippets

About Go Cookbook

A collection of practical, real-world Go snippets to help developers solve common problems

Who is this for?

Go developers of all levels who want to find quick solutions to common programming challenges.

Why use Go Cookbook?

Save time with ready-to-use code snippets that follow best practices and are easy to implement.

How to contribute?

Share your own Go recipes by submitting a PR to our GitHub repository.

Snippet quality

All snippets are tested, documented, and follow idiomatic Go patterns.