Quantcast
Channel: Alex Edwards
Browsing all 71 articles
Browse latest View live

HTTP Method Spoofing in Go

A.K.A. HTTP method overriding. As a web developer you probably already know that HTML forms only support the GET and POST HTTP methods. If you want to send a PUT, PATCH or DELETE request you need to...

View Article


Image may be NSFW.
Clik here to view.

Streamline Your Sublime Text + Go Workflow

For the past couple of years I've used Sublime Text as my primary code editor, along with the GoSublime plugin to provide some extra IDE-like features. But I've recently swapped GoSublime for a more...

View Article


How to Hash and Verify Passwords With Argon2 in Go

Thanks to Andreas Auernhammer, author of the golang.org/x/crypto/argon2 package, for checking over this post before publication. If you're planning to store user passwords it's good practice...

View Article

Image may be NSFW.
Clik here to view.

An Overview of Go's Tooling

Occasionally I get asked “why do you like using Go?” And one of the things I often mention is the thoughtful tooling that exists alongside the language as part of the go command. There are some tools...

View Article

Using PostgreSQL JSONB with Go

PostgreSQL provides two JSON-related data types that you can use — JSON and JSONB. The principal differences are: JSON stores an exact copy of the JSON input. JSONB stores a binary representation of...

View Article


Interfaces Explained

For the past few months I've been running a survey which asks people what they're finding difficult about learning Go. And something that keeps coming up in the responses is the concept of interfaces....

View Article

How to Parse a JSON Request Body in Go

Let's say that you're building a JSON API with Go. And in some of the handlers — probably as part of a POST or PUT request — you want to read a JSON object from the request body and assign it to a...

View Article

How to Manage Database Timeouts and Cancellations in Go

One of the great features of Go's database/sql package is that it's possible to cancel database queries while they are still running via a context.Context instance. On the face of it, usage of this...

View Article


Surprises and Gotchas When Working With JSON

This is a list of things about Go's encoding/json package which, over the years, have either confused or surprised me when I first encountered them. Many of these things are mentioned in the official...

View Article


Custom command-line flags with flag.Func

One of my favorite things about the recent Go 1.16 release is a small — but very welcome — addition to the flag package: the flag.Func() function. This makes it much easier to define and use custom...

View Article

Image may be NSFW.
Clik here to view.

How to correctly use Basic Authentication in Go

When searching for examples of HTTP basic authentication with Go, every result I could find unfortunately contained code which is either out-of-date (i.e. doesn't use the r.BasicAuth() functionality...

View Article

I18n in Go: Managing Translations

Recently I've been building a fully internationalized (i18n) and localized (l10n) web application for the first time with Go's golang.org/x/text packages. I've found that the packages and tools that...

View Article

Image may be NSFW.
Clik here to view.

Which Go router should I use? (with flowchart)

When you start to build web applications with Go, one of the first questions you'll probably ask is "which router should I use?". It's not an easy question to answer, either. There are probably more...

View Article


An Introduction to Handlers and Servemuxes in Go

Processing HTTP requests with Go is primarily about two things: handlers and servemuxes. If you’re coming from an MVC-background, you can think of handlers as being a bit like controllers. Generally...

View Article

Quick tip: Change URL query params in Go

In this short post we're going to discuss how to add, modify or delete URL query string parameters in Go. To illustrate, we'll look at how to change this URL:...

View Article


Image may be NSFW.
Clik here to view.

Continuous integration with Go and GitHub Actions

In this post we're going to walk through how to use GitHub Actions to create a continuous integration (CI) pipeline that automatically tests, vets and lints your Go code. For solo projects I usually...

View Article

Quick tip: Easy test assertions with Go generics

Now that Go 1.18 has been released with support for generics, it's easier than ever to create helper functions for your test assertions. Using helpers for your test assertions can help to: Make your...

View Article


How to use go run to manage tool dependencies

When you're working on a project it's common for there to be some developer tooling dependencies. These aren't code dependencies, but rather tools that you run on as part of the development, testing,...

View Article

Flow: A delightfully tiny but powerful HTTP router for Go

Last year I wrote a new HTTP router for Go called Flow. I've been using it in production on this site and in a couple of other projects since, and I'm pretty happy with how it's working out so decided...

View Article

The ‘fat service’ pattern for Go web applications

In this post I'd like to talk about one of my favorite architectural patterns for building web applications and APIs in Go. It's kind of a mix between the service object and fat model patterns — so I...

View Article
Browsing all 71 articles
Browse latest View live