In golang nil is not always equal to nil

Even experienced go developers can get tripped up by this one edge case in golang. In golang nil is not always equal to nil. A variable that holds an interface can have a nil value but still pass a nil check. An interface value is internally stored as two words: Type word – the dynamic type of the value stored in the interface. Value word – the actual value itself (or a pointer to it)....

My Breakdown in Local Ai

$0.11 in API costs for a single query I couldn’t believe it when I saw the API cost breakdown. I had uploaded less than 1GB of documents and attempted to extract summary information. Boom $0.11 without even a single follow up question. 1KWh of power cost $0.07 where I live. For the price of one query I can run a Local AI workstation for multiple hours with as many queries as I want....

Let's add AI to the on-call rotation

Every developer knows the anxiety of holding the pager, the notification that means drop everything and open your work laptop. I’m looking forward to a future where we can give this responsibility to an AI as a first line of defence. When the pager goes off, we have the ability to first send all the information that would be sent to the on call engineer to an AI Agent. This agent would be able to see the problem and call tools like:...

Real Time Audio Chat Server

Building a Real-time Audio Chat Application with Go and WebSockets from Scratch This guide will walk you through creating a real-time audio chat application using Go and WebSockets, built entirely from scratch without cloning an existing repository. We’ll set up the project structure, implement a WebSocket server to pair two clients for audio communication, and create a simple frontend to capture and play audio in the browser. By the end, you’ll have a functional application where two users can connect and talk in real-time....

How to Build a QR Code Generator Service in Go: A Step-by-Step Guide

QR codes have become an essential tool for bridging the physical and digital worlds. From enabling quick logins on smart TVs to sharing promotional content on printed cards, QR codes are versatile and easy to use. In this blog post, I’ll walk you through how to build your own QR code generator service using Go. We’ll create a simple web application that takes a URL as input, generates a QR code, and displays it to the user....

Mastering Go Application Design: Make an API Request With the Default Go HTTP Client

Executing HTTP requests in golang can be used to create an api integration and automate workflows. The standard library “net/http” package can be used to create a request object and the DefaultClient can be used to execute the request. We can expand this basic example to create complex interactions between backend services communicating over HTTP APIs. Playground: https://go.dev/play/p/AGV2OyqN-a6 package main import ( "io" "net/http" ) func main() { // create a new request req, err := http....

Mastering Go Application Design: Building a Basic CLI from Scratch with Only the Standard Library

Golang has built in support for creating CLI applications that accept command line flags and arguments. The “flag” package has convenient methods for reading in options as typed variables, it also supports creating default help text. CLI applications are useful for creating developer tooling, especially when you can import critical parts of the codebase into a simple cli. Playground: https://go.dev/play/p/UHuXCNgQB8j package main import "flag" var ( // define the command line arguments customerID *int = flag....

Mastering Go Application Design: Simplify Complex Systems With a Diagram

Diagraming your applications can be a useful exercise. It can give you a chance to think clearly about what already exists, what you plan to create and how it will work. Some of the best systems I’ve designed were complete mysteries to me, then I took time to diagram what already existed and it helped me see what needed to be created next. Diagrams can also be extremely valuable documentation, even if they are slightly out of date....

Mastering Go Application Design: Protobuf vs JSON Encoding

Protobuf and JSON are two popular methods for structuring data for efficient storage and transfer. Protobuf is more efficient than JSON in terms of byte array size, but it takes longer to convert an object to a byte array and changes to the message structure require code generation. When Protobuf is used to replace JSON at large scale, it can save massive amounts of bandwidth. Example Github Repository here Protobuf file Marshal Lets start with some go code with the protos already defined and working....

Mastering Go Application Design: HTTP Path Parameters (Part 2)

Part 1 , Part 2 HTTP Api’s often use the url path to identify resource name, id and possibly an action. These parts of the URL path are divided by the / character. Here is an example of using path parameters to implement a key value store where data is saved using the following request GET /set/$key/$value and retrieved using the request GET /get/$key using only the standard library. Go Playground: https://go....