Skip to content

Instantly share code, notes, and snippets.

View lavalamp's full-sized avatar

Daniel Smith lavalamp

View GitHub Profile
@lavalamp
lavalamp / toplevelnamechange.go
Created September 2, 2020 17:54
Change a "top level" name (e.g. a package reference) in a go file
package main
import (
"bytes"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"io/ioutil"
"log"

Keybase proof

I hereby claim:

  • I am lavalamp on github.
  • I am veritas (https://keybase.io/veritas) on keybase.
  • I have a public key ASAEolNUkmcVxXB2QtL7HnPFDLvSae3_X3rw59v7hEOSFAo

To claim this, I am signing this object:

@lavalamp
lavalamp / The Three Go Landmines.markdown
Last active February 16, 2024 12:16
Golang landmines

There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.

All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.

  1. Loop variables are scoped outside the loop.

What do these lines do? Make predictions and then scroll down.

func print(pi *int) { fmt.Println(*pi) }