Go code examples
9 short, tested snippets. Pick one to see the code with notes, or search Zest for something specific, such as “go read a file”.
- Read a filedata, err := os.ReadFile("data.txt")
- HTTP serverpackage main
- Goroutines and WaitGroupvar wg sync.WaitGroup
- Struct and methodtype User struct {
- JSON encode and decodetype Item struct {
- Error handlingres, err := doThing()
- HTTP GET requestclient := &http.Client{Timeout: 10 * time.Second}
- Loop over slices and mapsfor i, v := range []string{"a", "b"} {
- Hello worldpackage main