Don’t Go To Casting Hell; Use Default Native Types in Go

hell red sky

Go is strongly typed, and with that, we get many options for simple variable types like integers and floats. The problem arises when we have a uint16, and the function we are trying to pass it into takes an int. We find code riddled with int(myUint16) that can become slow and annoying to read. Go’s … Read more Don’t Go To Casting Hell; Use Default Native Types in Go

Range Over Ticker In Go With Immediate First Tick

Profile   Tick Toc Croc

The Go standard library has a really cool type – Ticker. Tickers are used when you want to do something at a regular interval, similar to JavaScript’s setInterval. Here’s an example: As per the docs, a ticker is a struct that holds a receive-only channel of time.Time objects. In the example at the beginning of … Read more Range Over Ticker In Go With Immediate First Tick

Connecting To RabbitMQ In Golang

photo 1557431518 26e2500b8680

RabbitMQ is a message broker that’s great for pub-sub systems in a micro-services architecture. At my current day job, we use RabbitMQ in our data ingest pipeline. All the services are written in Go, and they all push data through hundreds of RabbitMQ queues. Let’s take a look at how to efficiently publish and subscribe … Read more Connecting To RabbitMQ In Golang

Using ‘Go Generate’ To Deploy Multi-Process Apps

GE 740x520 1

In microservice architectures, it is fairly common to have a project that includes different worker types. A Makefile can be used to manage the creation of multiple programs, but the Go toolchain has a great tool that can be used as well, go generate. Here are some examples of how we take advantage of ‘go … Read more Using ‘Go Generate’ To Deploy Multi-Process Apps

Use Anonymous Structs For JSON Marshalling in Go

photo 1493476523860 a6de6ce1b0c3

Go is a language built for the web. The Go standard library comes with everything we need to stand up a production web server. Today we are going to explore marshaling JSON using anonymous structs. Anonymous structs can help keep API handlers clean and simple. What Is A Struct? Go’s structs are typed collections of fields. They’re … Read more Use Anonymous Structs For JSON Marshalling in Go

Announcing Go-TinyTime, Go-TinyDate’s Sister Package

tinyclock

time.Time is the perfect choice for most cases, it even comes in the standard library! The problem is that the time.Time{} struct uses more than 24 bytes of memory under most conditions. Go-TinyTime solves this problem by restricting the available dates to the range between 1970 – 2106, and only supporting UTC timezones. This brings … Read more Announcing Go-TinyTime, Go-TinyDate’s Sister Package

Golang Conversions – Ints To Strings And Strong Typing

photo 1500589177368 c810ea3db799

Go is a strongly typed language, which means at any point a developer should know exactly what type of value they are dealing with. For example, if we have a function that prints a string, we can’t just give it an integer and expect it to work. We have to cast it to a string … Read more Golang Conversions – Ints To Strings And Strong Typing

How To Separate Library Packages in Go

photo 1550535424 b498819c412f

I’ve often seen, and have been responsible for, throwing code into packages without much thought. I’ve quickly drawn a line in the sand and started putting code into different folders (which in Go are different packages by definition) just for the sake of findability. What is a Package? In Go, code is organized into packages. … Read more How To Separate Library Packages in Go

I Wrote Go-TinyDate, The Missing Golang Date Package

package

time.Time makes dealing with dates and times in Go a breeze, and it even comes bundled in the standard library! However, a time.Time{} struct uses more than 24 bytes of memory under most conditions, and I’ve run into situations where I need to store millions of them in memory, but all I really needed was … Read more I Wrote Go-TinyDate, The Missing Golang Date Package

Golang Mutexes – What Is RWMutex For?

Golang is King when it comes to concurrency. No other language has so many tools right out-of-the-box, and one of those tools is the standard library’s sync.Mutex{}. What Problem Do Mutexes Solve? We don’t want multiple threads accessing the same memory at the same time. In concurrent programming, we have many different threads (or in … Read more Golang Mutexes – What Is RWMutex For?