1. Learn the Basics
Learn the common concepts of Go like variables, loops, conditional statements, functions, data types, and so on. A good starting point for go basics is its Go’s official docs.
- official Go Tutorial
- article W3 Schools Go Tutorial
- feed Explore top posts about Golang
◇Basic Syntax
Learn about the basic syntax of Go, such as how the Go programs are executed, package imports, main function, and so on.
- official Go Tutorial: Getting started
- article Go by Example: Hello World
- article W3schools: Go Syntax
◇Variables in Go
Variable is the name given to a memory location to store a value of a specific type. Go provides multiple ways to declare and use variables.
- official Go Variables
- article Go by Example: Variables
- article w3schools Go variables
◇Data Types(bool | int, int8/16/32/64 | byte | unit, unit8/16/32/64 | rune | float32/64 | complex64/128 | unitptr)
Go is a statically typed programming language, which means each variable has a type defined at first and can only hold values with that type. There are two categories of types in Go: basics types and composite types.
- official Tour of Go: types
- article Go types with examples
- article Data Types
◇For Loop
Go has only one looping construct, the for loop. The basic for loop has three components separated by semicolons:
-
the init statement: executed before the first iteration
-
the condition expression: evaluated before every iteration
-
the post statement: executed at the end of every iteration
-
official For Loop in Golang
-
official Effective Go: For loop
-
article Go by Example: For loop
-
article 5 Basic for Loop Patterns
◇Range
range
is used with for loops to iterate over each element in arrays, strings and other data structures.
- official Go Ranges
- article Go by Example: Range
- article Go ranges basic patterns
◇Conditional Statements
Conditional statements are used to run code only if a certain condition is true. Go supports:
-
if
statements -
if...else
statements -
switch...case
statements -
official Effective Go: if statement
-
article Go by Example: If-Else
-
article Golang If-Else Statements
-
article Golang Switch Case Programs
◇Errors/Panic/Recover
In lieu of adding exception handlers, the Go creators exploited Go’s ability to return multiple values. The most commonly used Go technique for issuing errors is to return the error as the last value in a return.
A panic typically means something went unexpectedly wrong. Mostly used to fail fast on errors that shouldn’t occur during normal operation, or that we aren’t prepared to handle gracefully.
Panic recovery in Go depends on a feature of the language called deferred functions. Go has the ability to guarantee the execution of a function at the moment its parent function returns. This happens regardless of whether the reason for the parent function’s return is a return statement, the end of the function block, or a panic.
- official Error handling and Go
- official Go Defer, Panic and Recover
- article Effective error handling in Go
◇Functions, multiple/named returns
A function is a block of code that performs a specific task. It’s a reusable unit of code that can be called from other parts of your program. Functions help you organize your code, make it more modular, and improve readability.
- official Effective Go: Functions
- article Go by Example: Functions
- article Functions in Go
◇Packages, imports and exports
Packages are the most powerful part of the Go language. The purpose of a package is to design and maintain a large number of programs by grouping related features together into single units so that they can be easy to maintain and understand and independent of the other package programs. This modularity allows them to share and reuse. In Go language, every package is defined with a different name and that name is close to their functionality like “strings” package and it contains methods and functions that only related to strings.
- official Go Packages Explorer
- official Standard library
- official How to Manage External Dependencies in Go
- article How to create a package in Go
◇Type Casting
Go doesn’t support automatic type conversion, but it allows type casting, which is the process of explicitly changing the variable type.
- official Tour of Go: Type Casting Basics
- article Go Docs: Type Casting
◇Type Inference
Type inference gives go the capability to detect the type of a value without being explicitly indicated , hence the possibility to declare variables without providing its type at first
- official Tour of Go: Type Inference
- article Go Variables: Type Inference
◇Arrays
In Go an array
is a collection of elements of the same type with a fixed size defined when the array is created.
- official Go Arrays
- official Effective Go: Arrays
- video Learn Go Programming - Arrays
◇Slices
Slices are similar to arrays but are more powerful and flexible. Like arrays, slices are also used to store multiple values of the same type in a single variable. However, unlike arrays, the length of a slice can grow and shrink as you see fit.
- official Go Slices
- official Effective Go: Slices
- iarticle Slices in Go
- video Learn Go Programming - Slices
◇Maps
Maps are the data structure in Go, where we use whenever we want to have mappings between key:value pairs. They have flexibility in terms of removing or adding elements into them. Maps do not allow duplicate entries while data are kept unordered.
- official Go Maps
- official Effective Go: Maps
- article Maps in Go
- video Golang Tutorial #15 - Maps (by Tech With Tim on YouTube)
◇make()
Golang’s built-in function make, helps us create and initialize slices, maps and channels, depending on the arguments that are provided to the function.
- official Effective Go: Allocation with make
- article Create a slice with make
- article Create a map with make
- article Create a channel with make
◇Structs
Structs are user-defined types that help us create a collection of data describing a single entity.
- official Go Structs
- article Go by Example: Structs
- video Structs in Go
- video Struct tags and creating own tags through reflection
2. Going Deeper
Diving deeper into Golang involves exploring the language’s more advanced features and best practices to harness its full potential. Once you’ve mastered the basics, advancing your knowledge includes understanding complex aspects of Go that can significantly improve your code’s performance, readability, and maintainability.
- article Mastering Advance GO
◇Go Modules
Go modules are a group of related packages that are versioned and distributed together. They specify the requirements of our project, list all the required dependencies, and help us keep track of the specific versions of installed dependencies.
- official Go Modules
- article DigitalOcean: How to use Go Modules
- video Go Modules
- feed Explore top posts about Golang
◇Marshalling & Unmarshalling JSON
JSON (JavaScript Object Notation) is a simple data interchange format. Syntactically it resembles the objects and lists of JavaScript. It is most commonly used for communication between web back-ends and JavaScript programs running in the browser, but it is used in many other places, too.
- official JSON
- article Guide to JSON in Golang
- article JSON to GO
- article Comprehensive Guide to using JSON in Go
◇Types, Type Assertions, Switches
Types in Golang specify the data type that a valid Go variable can hold. Golang has four categories of Types including Basic, Aggregate, Reference, and Interface Types. Type assertions in Golang provide access to the exact type of variable of an interface.
- official Types Assertions
- video Go Syntax - Type Assertions
◇Interfaces
An interface in Go, is a type that defines a set of methods. If we have a type (e.g. struct) that implements that set of methods, then we have a type that implements this interface.
- official Go Interfaces
- official Effective Go: Interfaces
- article Go by Example: Interfaces
- video Golang Tutorial #22 - Interfaces (by Tech With Tim on YouTube)
- video Understanding Go Interfaces
◇Context
The context
package provides a standard way to solve the problem of managing the state during a request. The package satisfies the need for request-scoped data and provides a standardized way to handle: Deadlines, Cancellation Signals, etc.
- official Go Context
- article Go by Example: Context
- article Digital Ocean: How to Use Contexts in Go
- video Context in Go
- video Understanding Contexts in Go
◇Goroutines
Goroutines allow us to write concurrent programs in Go. Things like web servers handling thousands of requests or a website rendering new pages while also concurrently making network requests are a few example of concurrency. In Go, each of these concurrent tasks are called Goroutines
.
- official Goroutines
- official Effective Go: Goroutines
- article Go by Example: Goroutines
- video GoRoutines
- video Understanding Concurrency
- feed Explore top posts about Golang
◇Channels
Channels are the pipes that connect concurrent goroutines. You can send values into channels from one goroutine and receive those values into another goroutine.
Channels are a typed conduit through which you can send and receive values with the channel operator, <-
.
- official Channels
- official Effective Go: Channels
- article Go by Example: Channels
- article Channels in Golang
- video Channels
- video Golang Channel Basics You must Know!
◇Buffer
The buffer
belongs to the byte package of the Go language, and we can use these package to manipulate the byte of the string.
- official Buffer Examples
- article Buffer
◇Select
The select
statement lets a goroutine wait on multiple communication operations.
A select
blocks until one of its cases can run, then it executes that case. It chooses one at random if multiple are ready. The select
statement is just like switch statement, but in the select statement, case statement refers to communication, i.e. sent or receive operation on the channel.
- official Select
- article Go by Example: Select
- video Select Statement
◇Mutex
Go allows us to run code concurrently using goroutines. However, when concurrent processes access the same piece of data, it can lead to race conditions. Mutexes are data structures provided by the sync package. They can help us place a lock on different sections of data so that only one goroutine can access it at a time.
- article Using a Mutex in Go with Examples
- article Sync Package
◇Scheduler
Go Scheduler allows us to understand more deeply about how Golang works internally. In terms of logical processors, cores, threads, pool cache, context switching etc. The Go scheduler is part of the Go runtime, and the Go runtime is built into your application.
- article OS Scheduler - 1
- article Go Scheduler - 2
- article Illustrated Tales of Go Runtime Scheduler
- video Go scheduler: Implementing language with lightweight concurrency
◇Generics
Go Generics is a feature that allows you to write functions, data structures, and algorithms that can work with any type. This is a powerful feature that can help you write more flexible and reusable code.
- official Generics
- official Go Blog: Generics
- article Go by Example: Generics
- video Generics Explained
◇Pointers
Go pointers are a powerful feature that allows you to work with memory addresses directly. They are used to store the memory address of a variable. This can be useful when you need to pass a large amount of data to a function or when you need to modify the value of a variable inside a function.
- official Pointers
- article Go by Example: Pointers
- video YouTube: Pointers
3. Building CLI Applications
Command line interfaces (CLIs), unlike graphical user interfaces (GUIs), are text-only. Cloud and infrastructure applications are primarily CLI-based due to their easy automation and remote capabilities.
Go applications are built into a single self contained binary making installing Go applications trivial; specifically, programs written in Go run on any system without requiring any existing libraries, runtimes, or dependencies. And programs written in Go have an immediate startup time—similar to C or C++ but unobtainable with other programming languages.
- official Command-line Interfaces (CLIs)
- feed Explore top posts about Golang
◇Cobra
Cobra is a library for creating powerful modern CLI applications.
- official Cobra Website
- OpenSource Cobra Github
- article Cobra Package Documentation
- video How to write beautiful Golang CLI
◇Urfave CLI
Urfave CLI is a simple, fast, and fun package for building command line apps in Go.
- OpenSource Urfave CLI
- article Urfave Website
- article How to Build cli in Go
- article Building CLI using urfave cli
- feed Explore top posts about CLI
4. ORMs
Object–relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between type systems using object-oriented programming languages. This creates, in effect, a “virtual object database”, hence a layer of abstraction, that can be used from within the programming language. Most common ORM library in Go is GORM.
◇GORM
The GORM is fantastic ORM library for Golang, aims to be developer friendly. It is an ORM library for dealing with relational databases. This gorm library is developed on the top of database/sql package. The overview and feature of ORM are: Full-Featured ORM (almost)
- official Gorm
- article Gorm Package
- video GORM And MYSQL
5. Web Frameworks
There are several famous web frameworks for Go. Most common ones being:
-
Beego
-
Gin
-
Revel
-
Echo
-
GoFiber
-
OpenSource Comparison of Web Frameworks
◇Beego
Beego is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services. It is inspired by Tornado, Sinatra and Flask. beego has some Go-specific features such as interfaces and struct embedding.
- OpenSource Beego/Beego
◇Gin
Gin is a high-performance HTTP web framework written in Golang (Go). Gin has a martini-like API and claims to be up to 40 times faster. Gin allows you to build web applications and microservices in Go.
- OpenSource Gin
- article Gin Web Framework
- feed Explore top posts about Golang
◇Revel
Revel organizes endpoints into Controllers. They provide easy data binding and form validation. Revel makes Go Templates simple to use at scale. Register functionality to be called before or after actions.
- official Revel
- article Revel Packages
◇Echo
Echo is a performance-focused, extensible, open-source Go web application framework. It is a minimalist web framework that stands between stdlib + router and a full-stack web framework.
- official Echo Website
- OpenSource Echo
◇Gofiber
Go Fiber is an Express-inspired framework for Golang. Go Fiber is a web framework built on top of fast HTTP. It can be used to handle operations such as routing/endpoints, middleware, server request, etc.
- official Official Docs
- OpenSource Fiber
◇Gorilla
Gorilla is a web toolkit for the Go programming language that provides useful, composable packages for writing HTTP-based applications.
- official Gorilla Toolkit
- OpenSource Gorilla
6. Logging
Go has built-in features to make it easier for programmers to implement logging. Third parties have also built additional tools to make logging easier.
- article Logging in Go: Choosing a System and Using it
- article Logging in Golang – How to Start
- feed Explore top posts about Logging
◇log/slog
The log
and log/slog
(since go 1.21) packages are the standard logging packages in Go. These packages provides a simple logging API that can be used to log messages to the console or to a file.
- official Documentation: log
- official Documentation: slog
- official Go Blog: Structured Logging with slog
- article Go by Example: Logging
- feed Explore top posts about Logging
◇Zap
Blazing fast, structured, leveled logging in Go.
- OpenSource Zap
◇Zerolog
The zerolog package provides a fast and simple logger dedicated to JSON output.
Zerolog’s API is designed to provide both a great developer experience and stunning performance. Its unique chaining API allows zerolog to write JSON (or CBOR) log events by avoiding allocations and reflection.
- OpenSource Zerolog
7. Real time communication
Just as it says in the name, real-time communication is the handling of requests concurrently and efficiently. Whether it is a chat/messaging app, an email service, a game server or any collaborative online project (for example, Excalidraw), there are a few different ways of handling real-time communication, but the most common is through the use of WebSockets. Other options for handling real-time communications include MQTT protocol and server-sent events, among others.
- video Golang websocket
◇Melody
Melody is websocket framework based on gorilla/websocket that abstracts away the tedious parts of handling websockets. It gets out of your way so you can write real-time apps.
◇Centrifugo
Centrifugo is an open-source scalable real-time messaging server. Centrifugo can instantly deliver messages to application online users connected over supported transports (WebSocket, HTTP-streaming, SSE/EventSource, GRPC, SockJS, WebTransport). Centrifugo has the concept of a channel – so it’s a user-facing PUB/SUB server.
- official Getting Started
- OpenSource Centrifugo
8. API Clients
An API client is a set of tools and protocols that operate from an application on a computer. They help you to bypass some operations when developing a web application rather than reinventing the wheel every time. Using a client API is a great way to speed up the development process.
- article API Clients
- feed Explore top posts about Golang
◇REST
REST (Representational State Transfer) API (Application Programming Interface) is used to deliver user functionality when dealing with websites. HTTP requests are used to communicate with REST APIs so users can navigate a URL website. These URLs can return certain information that is stored as part of the API.
- official Tutorial
- video RESTful APIs Series
- feed Explore top posts about REST API
Heimdall
Heimdall is an HTTP client that helps your application make a large number of requests, at scale. With Heimdall, you can:
-
Use a hystrix-like circuit breaker to control failing requests
-
Add synchronous in-memory retries to each request, with the option of setting your own retrier strategy
-
Create clients with different timeouts for every request All HTTP methods are exposed as a fluent interface.
-
OpenSource Heimdall
Grequests
Golang implementation of Python Grequests library(one of well known HTTP Library in Python).
Features:
-
Responses can be serialized into JSON and XML
-
Easy file uploads
-
Easy file downloads
-
Support for the following HTTP verbs GET, HEAD, POST, PUT, DELETE, PATCH, OPTIONS
-
OpenSource Grequests
◇GraphQL
GraphQL
is a query language for APIs, it offers a service that prioritizes giving just the data that the client requested and no more. Besides, you don’t need to be worried about breaking changes, versioning and backwards compatibility like REST APIs. Therefore you can implement your version and auto-document your API just by using GraphQL
.
- roadmap Visit Dedicated GraphQL Roadmap
- official Learn GraphQL
- official GraphQL Tutorials
- article Red Hat: What is GraphQL?
- article Digital Ocean: An Introduction to GraphQL
- video GraphQL Full Course - Novice to Expert
- video Beginner GraphQL Series (by Ben Awad on YouTube)
- feed Explore top posts about GraphQL
Graphql-go
A GraphQL
package for Go
.
- OpenSource Graphql
- article Graphql-go homepage
- article Graphql-go documentation
- video GraphQL-Go - Golang Tutorial (by TechPractice on YouTube)
- feed Explore top posts about GraphQL
Gqlgen
According to their documentation, it’s a Golang library for building GraphQL servers without much effort.
- official Gqlgen Documentation
- article Introducing gqlgen: a GraphQL Server Generator for Go
- video GraphQL in Go - GQLGen Tutorial (by acklackl on YouTube)
9. Testing Go Code
Go has a built-in testing command that we can use to test our program.
- official Go Tutorial: Add a Test
- article Go by Example: Testing
- article YourBasic Go: Table-driven unit tests
- article Learn Go with Tests
- feed Explore top posts about Testing
10. Tools for Microservices
Microservices are an architectural approach to software development that allows the creation of a distributed application from deployable services that allow communication through a well-defined API. Being a solution to monoliths.
- official Microservice Patterns and Resources by Chris Richardson
- article Introduction to Microservices
- article Microservices AntiPatterns and Pitfalls - Mark Richards
- article Building Microservices, 2nd Edition - Sam Newman
- feed Explore top posts about Microservices
◇Watermill
Watermill is an event streaming library for handling asynchronous requests in Go. It provides multiple implementations for pub/sub. For example, you can use conventional pub/sub systems like Kafka or RabbitMQ, as well as HTTP or MySQL binlog, depending on your use case.
- official Watermill Website
- official Watermill Documentation
◇Rpcx
Rpcx is a RPC (Remote Procedure Call) framework like Alibaba Dubbo and Weibo Motan. Some of the advantages on using Rpcx:
-
Simple: easy to learn, easy to develop, easy to integrate and easy to deploy
-
Performance: high performance (>= grpc-go)
-
Cross-platform: support raw slice of bytes, JSON, Protobuf and MessagePack. Theoretically it can be used with java, php, python, c/c++, node.js, c# and other platforms
-
Service discovery and service governance: support zookeeper, etcd and consul.
-
official Rpcx Official Website
-
official Rpcx Documentation
-
OpenSource Rpcx
◇Go-kit
Go kit is a programming toolkit for building microservices (or elegant monoliths) in Go. it solves common problems in distributed systems and application architecture so you can focus on delivering business value.
- official Go-kit Website
- article Microservices in Go using the Go kit
- video Building Microservices with the Go Kit Toolkit
- feed Explore top posts about Golang
◇Micro
It is an API first development platform. It leverages the microservices architecture pattern and provides a set of services which act as the building blocks of a platform.
- official Micro Website
- OpenSource Micro
◇go-zero
go-zero is a web and rpc framework with lots of engineering best practices builtin. It’s born to ensure the stability of the busy services with resilience design, and has been serving sites with tens of millions users for years.
- official Go-zero
- official Go-zero Docs
- OpenSource Go-Zero
- feed Explore top posts about Golang
◇Protocol Buffers
Protocol Buffers(Protobuf) is a free, open-source, language-neutral, platform-neutral, extensible data format used to serialize structured data. It’s like JSON, except it’s smaller and faster, and it generates native language bindings.
Some of the advantages of using protocol buffers include:
-
Compact data storage
-
Fast parsing
-
Availability in many programming languages
-
Optimized functionality through automatically-generated classes
-
OpenSource Protobuf
-
article Protobuf Doc
-
article Protobuf with Go
◇gRPC-Go
Go language implementation of gRPC(gRPC is a technology for implementing RPC APIs).
- official Basic tutorial introduction to gRPC in Go.
- OpenSource gRPC-go
- article gRPC-go Doc
- feed Explore top posts about gRPC
◇Grpc gateway
gRPC-Gateway creates a layer over gRPC services that will act as a RESTful service to a client. It is a plugin of protoc. It reads a gRPC service definition and generates a reverse-proxy server which translates a RESTful JSON API into gRPC.
- official Grpc-gateway Doc
- OpenSource Grpc-gateway
- feed Explore top posts about gRPC
◇Twirp
Twirp is a framework for service-to-service communication emphasizing simplicity and minimalism. It generates routing and serialization from API definition files and lets you focus on your application’s logic instead of thinking about folderol like HTTP methods and paths and JSON.
- official Getting Started
- OpenSource Twirp