Go

Organising Database Access in Go In the context of a web application what would you consider a Go best practice for accessing the database in (HTTP or other) handlers? The post analyses various design pattern they pros and cons.

Standard Package Layout - These are seen as big issues in the Go community but there’s another issue that’s rarely mentioned — application package layout.

Go best practices, six years in - Hints and practices to manage Golang project.

Don’t use Go’s default HTTP client - Go’s http package doesn’t specify request timeouts by default, allowing services to hijack your goroutines. Always specify a custom http.Client when connecting to outside services.

A Simple Web Scraper in Go and Web Scrapping With Golang are easy technic to parse HTML output of website. Most of the online bots are based on same technic to get required information

Iterating Over Slices In Go In Go everything is pass by value. We can pass by value the address of an object or pass by value a copy of an object. That includes function parameters, return values and when iterating over a slice, map or channel.

A Survey of Iterator (or Generator) Patterns in golang what the canonical iterator pattern in Go is: what’s the interface and the implementation? The post covers the basic options for a forward-only iterator (which admittedly simplifies the problem, mainly focusing on implementation rather than the appropriate interface, but this is also the most common type of iterator we need).

Golang RegExp uses linear time The regexp implementation provided by Go is guaranteed to run in time linear in the size of the input. This is a property not guaranteed by most open source implementations of regular expressions.

Type System

Type embedding in Go - Go does not provide the typical, type-driven notion of subclassing, but it does have the ability to “borrow” pieces of an implementation by embedding types within a struct or interface. In fact, type embedding is product type composition. The article explains basics behind the embedding.

Why doesn’t Go have variance in its type system? - It explain what co-, contra- and invariance are and what the implications for Go’s type system would be. In particular, why it’s impossible to have variance in slices.

Go and Sum Data Types - Sum types is a neat feature of some programming languages that lets us specify that a value might take one of several related types, and includes convenient syntax for pattern matching on these types at run-time.

Functional options on steroids - Functional options is a paradigm in Go for clean and extensible APIs popularized by Dave Cheney and Rob Pike. This post is about the practices that appeared around the pattern since it was first introduced.

Golang Unsafe Type Conversions and Memory Access Go is a strongly typed, you have to convert variable from one type to another to use in different parts of application. But sometimes you need to step around this type safety. It could be needed to optimization of bottle necks in high load systems, where every tick counts. Unsafe operation potentially could safe a lot of allocations. Unsafe also allows to hack into any struct field, including slices, strings, maps etc.

JSON

JSON and struct composition in Go - Say you are decoding a JSON object into a Go struct. It comes from a service that is not under your control, so you cannot do much about the schema. However, you want to encode it differently.

Dealing with JSON with non-homogeneous types in GO - Dynamic languages supports non-homogeneous schemas out-of-the-box (e.g. [ { "value": "123" }, { "value": 123 } ]). The post explains how to achieve this with type-safe approach in Golang.

Golang Parsing JSON into Interfaces - Interfaces are an incredibly powerful feature in Go, and JSON is one of the most ubiquitous serialization formats in use today. The post explains how to handle sum-type support in JSON with interfaces.

Channels

The Behavior Of Channels Any one who working with Go’s channels for the first time can make mistake of thinking about channels as a data structure. It’s best to forget about how channels are structured and focus on how they behave. Do not think about channels as a queue, think about one thing: signaling. A channel allows one goroutine to signal another goroutine about a particular event. Signaling is at the core of everything you should be doing with channels. The article depicts attributes of signalling system: Guarantee Of Delivery, State and With or Without Data. It relates to the question:

Do buffered channels maintain order?

Building an Unbounded Channel in Go The default un-buffered channels pass values from one goroutine to another, one at a time. The goroutine that writes to the channel blocks until another goroutine reads from the same channel. A buffered channel gives writers a bit more flexibility. When a channel is buffered, a set number of values can be written to the channel and not read before the channel blocks. It behaves like a synchronized queue with a bounded size. The post explains how to build Erlang’s style unbounded queues.

Go channels across many machines Concurrency is a great way to get more stuff done faster. Go channels are perfect for enabling multiple concurrent goroutines to safely communicate within a single process, but if we want to let multiple machines/nodes communicate in a similar way, we have to write completely different code and integrate with messaging queues, gRPC, or something else.

Language & Runtime

Scheduling In Go : Part I - OS Scheduler, Scheduling In Go : Part II - Go Scheduler and Scheduling In Go : Part III - Concurrency provide an understanding of the mechanics and semantics behind the scheduler in Go

Go AST Viewer - online tool for analysis and visualization of ast

Basic AST Manipulation, Basic AST Traversal in Go - simple technique to modify Go code using AST.

Performance

High Performance Go Workshop - The goal for this workshop is to give you the tools you need to diagnose performance problems in your Go applications and fix them. Through the day we’ll work from the small — learning how to write benchmarks, then profiling a small piece of code. Then step out and talk about the execution tracer, the garbage collector and tracing running applications.

Recursion And Tail Calls In Go Go does not optimize for recursion, even if tail calls are explicit. The post explains in details a Golang design of recursive calls and how to improve the memory consumption in recursive algorithms.

Errors

Why Go gets exceptions right explains how the error handling made right in Go to compare with C, C++ and Java.

Errors are values - Error handling in Go is different than other functional programming. Usually Either monad helps a lot. Go programmers miss a fundamental point about errors: Errors are values. The article shows a few patterns on error handling with Go.

Constant errors post show up the issue with sentinel error values in Go, it proposes alternative and type-safe solution to express errors using const. The approach advances error declaration and handling towards behaviour-based approach to inspect errors.

Inspecting errors Don’t assert errors for type, assert for behaviour. For package authors, if your package generates errors of a temporary nature, ensure you return error types that implement the respective interface methods. For package users, if you need to inspect an error, use interfaces to assert the behaviour you expect, not the error’s type.

Don’t just check errors, handle them gracefully in-depth explanation about error handling strategies.