Converting a Byte Array to String from a Node.JS `Buffer`, in Go

As noted in Converting a Byte Array to String with Buffer in Node.JS, you may encounter serialised Buffers when working with Node.JS projects. We may want to do something similar in Go, so how would we do this? package main import "fmt" func main() { a := []byte{104, 1...

(Generic) Functional Options Pattern

Targeted Go version: 1.18 Author(s): Changkun Ou Permalink: https://golang.design/research/generic-option The widely used self-referential function pattern as options, originally proposed by Rob Pike1, allows us to design a flexible set of APIs to help arbitrary configurations a...

Parsing the `Cookie` and `Set-Cookie` headers with Go

When working with HTTP services, you're likely to encounter cookies for passing around state. Although we could inspect the Cookie or Set-Cookie headers by hand, it's easier to have a tool automagically parse them for us, as they're not the easiest to read. I've created the follo...

Generating a Go HTTP Client from OpenAPI schemas

It's possible that you're using OpenAPI specifications to describe the format of your API, and as noted in Use a (JSON) Schema for the Interface Portion of your RESTful API is something I really recommend for codifying part of your API documentation. If you're on a Go project, yo...

Generating Go structs from OpenAPI schemas

It's possible that you're using OpenAPI specifications to describe the format of your API, and as noted in Use a (JSON) Schema for the Interface Portion of your RESTful API is something I really recommend for codifying part of your API documentation. If you're on a Go project, it...

Setting up GitLab CI for Go projects

As a heavy user of GitLab, I naturally want my Go projects to have an automated build/test process. While looking to set this up, I've found that a lot of the articles online are pre-Go modules, and back when you needed to install things into ~/go/src, which is no longer necessar...

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 test functions clean and clear; Keep test failure messages consistent...

Some thoughts on Go's unusual approach to identifier visibility

Providing a basic implementation of Ruby's `ARGF.read` in Go

While I write more Go command-line utilities, I find that I'm generally reading from stdin, but sometimes need to read input from files. I was happy using file redirection in my shell, for instance: $ ./helper <<< stdin $ ./helper < file.txtAs a lot of my scripts are...

Announcing GoReleaser v1.7 — The Go 1.18 release

The title would have been more creative if it was GoReleaser 1.18 as well… maybe… probably not.