Code Snippets

All Snippets

The latest code snippets.

Synchronize with WaitGroup

Wait for a batch of goroutines using sync.WaitGroup.

Author: chris

Sort Slice of Structs in Go

Sort a slice of structs with sort.Slice and a less func.

Author: chris

Regex FindAllString in Go

Compile a regex and pull every match out of a string.

Author: chris

SHA256 Hash in Go

Compute a SHA256 digest with the crypto/sha256 stdlib.

Author: chris

JSON Marshal and Unmarshal in Go

Encode and decode structs with the encoding/json stdlib.

Author: chris

HTTP GET in Go

Make an HTTP GET with net/http and read the body.

Author: chris

Write a File in Go

Atomically write bytes to disk with os.WriteFile.

Author: chris

Read a File to String in Go

Read an entire file into memory with os.ReadFile.

Author: chris