Skip to content

Instantly share code, notes, and snippets.

View gist:28157b77407097e8dd589734321c89ec
View fetch-all-questions.go
// StackOverflow analysis using its API in Go.
// Eli Bendersky []
// This code is in the public domain.
package main
import (
View task.json
"openapi": "3.0.1",
"info": {
"title": "Sample REST server",
"description": "TODO",
"version": "1.0.0"
"servers": [
"url": ""
View gist:28bca075e6b6e5d4821168f7a1d7d4d8
# TODO: add license?
openapi: 3.0.1
title: Sample REST server
description: TODO
version: 1.0.0
- url:
View gist:d3af6eb67de19be728df4d265ec15ff5
// Demonstrates async preemption in 1.14 vs. earlier versions
package main
import (
func f1() {
View gist:4b1d991f9971a887f82e3b1fa535d479
Title: Simple HTTP server
URL slug: httpserver
Description: A simple HTTP server serving two different routes using the default request multiplexer.
View gist:be8efeec5607700b89f97481008bf8b2
Title: Waiting for goroutines to finish
URL slug: waitgroup
Description: A WaitGroup provides a simple way to wait for a collection of goroutines to perform a task.
View gist:f9321b97b18a71328eca6ad21ba6d592
package main
import (
eliben / thoughts.rst
Last active Oct 12, 2018
Thoughts on the Go 2 Error Handling proposal
View thoughts.rst

TL;DR: The proposal looks good, except the handler chaining part, which adds a lot of magical complexity to cater to rare use cases. Chaining can always be added at a later stage without breaking backwards compatibility, if its lack is deemed unbearable.

As I see it, the biggest issues in current Go usage the proposal tackles are:

  1. Repeated sequences of if err != nil {return nil, err} littering Go code
  2. Lack of proper context in propagated errors (see (1) above)

To fix these issues, I believe the proposed check keyword with a single handler per function are sufficient. Using stacks of handlers for proper cleanup is best left to defer, which is already a familiar tool. Thus, handle should only exist as a default "report more context in case of an error and return the error" mechanism. Where a single handler appears insufficient because the nature of error handling required changes throug

View gist:9727758f4847d2e7d86e
foo = "\\"
bar = "\n"
manyescapes = "\\\\\\\\"
manyescapes2 = "\n\\\n\\"