Bossy Lobster

A blog by Danny Hermes; musing on tech, mathematics, etc.

Edit on GitHub

Go Duration, PostgreSQL Interval

Building a web application in Go and using PostgreSQL as the database is a real joy. Both of these tools are produced by incredibly vibrant open source projects. These projects represent some of the best attributes of the open source movement. When used in combination, occasionally idioms from Go don't …

Edit on GitHub

Decrypting Vault Ciphertext with a Context

In a previous post, I described a use case for customer provided keys with Vault. One of the implications of this was the need for decryption after a bulk data export. In that post, I gave a concrete example of decrypting Vault ciphertext directly with a customer provided key. However …

Edit on GitHub

Atomically Idempotent

Recently, I was analyzing some initialization code in Go with a teammate. The value being initialized was meant to be used in concurrent Go, so initialization had some requirement of atomicity. The code essentially boiled down to:

func (t *T) Start() {
    if atomic.LoadInt32(&t.State) == Started {
        return // Early Exit …
Edit on GitHub

Wrapping Behavior of context.WithValue()


Throughout the Go monorepo we use context.WithValue() to "stash" a global value on a root context. For example

ctx = logger.WithLogger(ctx, log)
// ... later ...
log := logger.GetLogger(ctx)

The implementations for stashing a logger.Log are in the same general form as most context wrapping helpers:

type loggerKey …
Edit on GitHub

Setting Per-Connection Timeouts with TypeORM

PostgreSQL Statement Timeout

For most applications that use a database, user-facing queries must complete in a reasonable amount of time. In order to ensure a maximum query time, PostgreSQL supports a statement_timeout which will cause a query to be cancelled if it exceeds the timeout:

$ psql
monsters_inc=> SHOW statement_timeout;
 statement_timeout …