Welcome to the GoLang Best Practices learning centre

golang-logo

Why Go

  1. Simplicity
    • Simplicity is prerequisite for reliability
    • There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.
  2. Readability
    • Readability is essential for maintainability
    • Programs must be written for people to read, and only incidentally for machines to execute.
    • The most important skill for a programmer is the ability to effectively communicate ideas.

Basics

Link Context
Control Flow Introduction
Functions Function grouping, Defer, Init, Avoid Init
Methods Value Methods, Pointer Methods
Names Best Practices, Identifiers, Comments, Code Documentation
Memory New, Make
Panic Best Practices, Recover from Panic
Defer Introduction, Panic Usage, How to write clean defer
Semi Columns How go compiler evaluate semicolons

Data Structure

Link Context
Arrays Introduction
Enums How to write Enums in Golang
Structs Struct visibility, Avoid embedding types in public structs, Initializing structs
Slices Introduction, Nil is a valid slice
Maps Existing Value, Map initialization
Errors Introduction, Custom Errors, Error Propagation and Handling, How to choose the error type, Wrapping Errors
Interfaces Type Switch, Generality, Pointer Methods

Interfaces

Link Context
Data Structure Basics Interface Guidelines
Usage - Do/Don't Do and Dont's and Testing
Polymorphism Static types, Dynamic types & Values
Type Assertion-Switch Type assertion and switch
Advance Best Practices and Examples Preemptive Interfaces

Concurrency

Link Context
Concurrency Introduction
Atomic Atomic
Goroutines Select, WaitGroup, ErrGroup
Go Scheduler Deep dive analyse how Go Scheduler works
Channels Buffered, Unbuffered, Channel Directions, Non Blocking Channel Operations
Channels Idioms Channel Idioms, Nil Channel,
Concurrency Patterns Worker Pool Pattern, Context Cancellation, or-channel, pipeline steam

Network

Link Context
HTTP Guideline Closing Body, HTTP Connections
Request Rate Limiter Limit the number of processed requests

Layout

Link Context
Format Style Format Code
Project-layout Package design
API structure API Internal Design

Testing

Link Context
Approaches Testing Approaches (Go Native vs BDT)
HTTP testing How to test http handler using httptest

Way to think

Link Context
Model Go Global State, Model Public API, Guard clause
Do and Dont's
  • Go Guidelines
  • Make the zero value useful
  • Slice and maps pointers to underlying data
  • Enums instead non-readable parameters
  • Use Raw String Literals to Avoid Escaping
Nice to know - Traps Go Specifics, Traps, Hidden Gems
Design Patterns Design Pattern in Go terms compared to OOP
Clean Architecture SOLID, Component Principles, GRASP
Go Design Pattern Real Life Examples Gives real life examples of using Decorator/Adapter/Chain-of-Responsibility (Middlewares) patterns and how the abstractions and layers are chosen and designed

Tips

Link Context
Timers How to set timers (using channels)
Tickers How to set tickers (using channels)
Time Time and time duration
Performance Small Performance improvements
Style Similar Declaration, Import Aliases, Reduce Nesting, Variables Scope, Unnecessary Else, Local variable declaration, Format Strings
Configurations Configure Environmental
Context Context Cancellation, Context Propagation, HTTP Server & Client, Context Values (Middleware Logging)

External References

Context Package - https://www.youtube.com/watch?v=LSzR0VEraWw&t=312s

Go

  1. Effective Go
  2. A Tour of Go

Interface Guide

  1. Interfaces in Go - Part 1
  2. Interfaces in Go - Part 2
  3. Interfaces in Go - Part 3