Handle CORS errors in gorilla websockets

TLD(W)R; // Allow everyone var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true }, } // Allow a specific domain var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { origin := r.Header.Get("Origin") return origin == "https://your.domain.com" }, } ...

December 11, 2024 · 4 min

Building a light weight clone of One million checkboxes

I first found out about the One million checkboxes website from a video on Prime’s youtube channel. I’ll admit that’s how I find about a lot of tech news these days. Ever since I found out about it I wanted to build it. I have recently started working on Go and wanted to build it directly in go instead of starting with python and then moving to go. While building this I learned two important things ...

December 4, 2024 · 10 min
Chris Ensey, Unsplash

Understanding Endianness with Go

Byte order is crucial when working with low-level data, and messing it up can lead to bugs that are difficult to track down. It doesn’t matter whether you’re working on a network protocol, reading binary data, or doing something fancy with hardware; understanding how data is represented in memory (and how it travels) is essential. But before we dive into the byte order mess, let’s get familiar with some key concepts. You’re gonna need these as you start looking at endianness (yes, it’s a real word). ...

November 28, 2024 · 6 min
Rob, Unsplash

[WIP] 1BRC: 1 Billion row challenge in Go!

The one billion row challenge has taken the world by a storm. Today we are going to see what is the reason behind this storm… Ok. Enough with the theatrics. I recently came across the 1 billion row challenge through a video on Primeagen. And instantly I wanted to try it out myself. I really liked the iterative approach taken by the author of the original article. I have recently started working on Go and I thought this would be a good way to get my hands dirty. ...

September 25, 2024 · 3 min
Mike Winkler, Unsplash

Understanding Ports, Sockets, WebSockets, and File Descriptors

If you’ve ever peeked under the hood of a web server, you’ve probably heard terms like ports, sockets, WebSockets, and file descriptors. They sound like a cocktail of tech jargon that could confuse even the best of us. But don’t worry—by the end of this article, you’ll understand what these things are and how they fit together like puzzle pieces in the world of networking and operating systems. What’s a Port, Anyway? Think of your computer as an apartment building. Inside, you’ve got a bunch of people (programs) living in their respective rooms. A port is like the apartment number on each door. It helps incoming traffic (data) know which program to knock on. ...

September 24, 2024 · 4 min

String formatting in Go!

fmt.Printf is like the Swiss Army knife of Go when it comes to string formatting. Whether you’re debugging, logging, or trying to impress your peers with some beautifully formatted output, fmt.Printf has your back. So, let’s dive into some of the most commonly used formatting verbs and flags in Go’s fmt package. The Basic Placeholders Here’s the bread and butter of fmt.Printf—the simple formatting verbs: %v: Prints the value in a default format. It’s like the wild card of formatting. ...

September 12, 2024 · 3 min

Go's Lesser-Known Control Mechanisms - defer, panic, and recover

Go is a wonderfully simple language—until it isn’t. Sure, you’ve got your basic if, for, switch, and even goto (although, let’s be honest, no one likes to admit using it). But when you dig deeper, Go offers some extra gems that make it stand out: defer, panic, and recover. These three can seem like the “mystery meat” of Go, but once you understand how they work, they’re not only powerful but also fun to use (with a few “gotchas” along the way). Let’s dive in. ...

September 9, 2024 · 4 min