This is a list about the corner cases that Go cannot do, and their work arounds.

Run all deferred functions of other goroutines when a goroutine panics

Uncaught panicking of one goroutine will exit the program without executing deferred functions of other goroutines.

Workaround: this is the standard behavior, C++ with RAII also has the same problem. Persist your data in a way that crashing will not cause data integrity issue.

Assigning to fields with short declaration notation

  • Issue: 6842
  • Status: Open & Unplanned

When it is useful:

if x.f, ok := f(); !ok {
	...
}

Workaround:

var ok bool
if x.f, ok = f(); !ok {
	...
}

Accessing unexported fields with reflect.Value.Interface method

When it is useful:

type S struct {
   val string
}

...

var s S

reflect.Value(s).Fields(0).Interface()

The code will panics with message:

reflect.Value.Interface: cannot return value obtained from unexported field or method

Workaround:

v := reflect.Value(s).Fields(0)
if v.Kind() == reflect.String {
	s := v.String()
}

Slice of array literal

e.g.

[3]int{1, 2, 3}[:]

Just use slice literal instead!