Skip to content

Instantly share code, notes, and snippets.


Steve Coffman StevenACoffman

View GitHub Profile
StevenACoffman / slog_console_handler.go
Created Nov 30, 2022 — forked from wijayaerick/slog_console_handler.go
Example ConsoleHandler for Logger
View slog_console_handler.go
// ConsoleHandler formats slog.Logger output in console format, a bit similar with Uber's zap ConsoleEncoder
// The log format is designed to be human-readable.
// Performance can definitely be improved, however it's not in my priority as
// this should only be used in development environment.
// e.g. log output:
// 2022-11-24T11:40:20+08:00 DEBUG ./main.go:162 Debug message {"hello":"world","!BADKEY":"bad kv"}
// 2022-11-24T11:40:20+08:00 INFO ./main.go:167 Info message {"with_key_1":"with_value_1","group_1":{"with_key_2":"with_value_2","hello":"world"}}
// 2022-11-24T11:40:20+08:00 WARN ./main.go:168 Warn message {"with_key_1":"with_value_1","group_1":{"with_key_2":"with_value_2","hello":"world"}}
View test.go
RunParallel(t, TestCase{
Steps: []TestStep{
Query: `
query getWorksheet($id: ObjectId!) {
worksheet(id: $id) {
StevenACoffman / main.go
Created Sep 2, 2022 — forked from pteich/main.go
Example for using go's sync.errgroup together with signal detection signal.Notify to stop all running goroutines
View main.go
package main
import (
StevenACoffman /
Created Aug 22, 2022
Differences in the Type System in GraphQL vs Go

Something worth pointing out is that the GraphQL and Go type systems have some pretty glaring differences, and, at least for me, it can be hard to know which mental model to reason with when working with Go code generated from a GraphQL schema. For instance, GraphQL requires explicitly stating that a type implements an interface in order for it to be used as that interface type.

Here's a list of type system differences:

  • Unions exist in GraphQL, but not Go, so they are somewhat mocked through Go interfaces
    • The Is{UnionName}() signpost functions leverage the Go compiler to help alleviate some of the confusion here
    • Without the signposts, a programmer implementing a query resolver would need likely need to jump to the GraphQL schema to figure out what types are included in the union
  • Interfaces in GraphQL differ from Go interfaces in two key ways
    • A GraphQL interface definition includes only fields, where Go interfaces contain methods
  • Getter functions are generated to preserve the
StevenACoffman /
Last active Aug 18, 2022
Testing Go module updates

So when we updated a few Go libraries, we wanted to run all the relevant tests... but not ALL tests. I thought this shell script one of my co-workers (@csilvers) used was very clever and handy:

git grep -l -e opentelemetry -e otelsql  '*.go' | grep -v testdata | xargs -n1 dirname | sed 's,^,./,' | sort -u | xargs gotestsum

Walking through what it does:

  • git-grep -l, --files-with-matches, -e <pattern>
  • grep -v, --invert-match Invert the sense of matching, to select non-matching lines. (exclude testdata dir matches)
  • xargs -n max-args Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the -x option is given, in which case xargs will
StevenACoffman /
Last active Jul 11, 2022
DACI - Driver, Approver, Contributor, Informed

Driver, Approver, Contributor, Informed (DACI)


The decision-making model we use, see below for acronym breakdown

The DACI acronym stands for the people who are involved in the decision-making process.

  • D = Driver. There is one driver and that person is responsible for getting stakeholders involved, gathering the input, and working with the Approver to ensure that the decision is made in the necessary timeframe. The driver need not be the person that leads the implementation of the decision.
  • A = Approver. The Approver is usually one person who is accountable for the results of the decision. The final decision is theirs alone. Less frequently, a decision will have more than one Approver, if it is affecting multiple areas of the organization and needs consensus among leads.
StevenACoffman / gcs-signed-url-main.go
Created Jun 28, 2022 — forked from pdecat/gcs-signed-url-main.go
Creating a GCS Signed URL without a Service Account Key from a GCE instance or a GKE Pod using Workload Identity
View gcs-signed-url-main.go
package main
import (

The New Jersey style (aka "Worse is Better") a model of software design and implementation which has the characteristics (in approximately descending order of importance):

  1. Simplicity: The design must be simple, both in implementation and interface. It is more important for the implementation to be simple than the interface. Simplicity is the most important consideration in a design.

  2. Correctness: The design should be correct in all observable aspects. It is slightly better to be simple than correct.

  3. Consistency: The design must not be overly inconsistent. Consistency can be sacrificed for simplicity in some cases, but it is better to drop those parts of the design that deal with less common circumstances than to introduce either complexity or inconsistency in the implementation.

  4. Completeness: The design must cover as many important situations as is practical. All reasonably expected cases should be covered. Completeness

View index.html
<!DOCTYPE html>
<html lang="en">
<div id="wrapper"></div>
<script src=""></script>
<script src=""></script>
<script src="./zchart.js"></script>