Skip to content

Instantly share code, notes, and snippets.

@flowchartsman
Created May 1, 2019 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flowchartsman/d428f9a013937997bd52f798e6a9e531 to your computer and use it in GitHub Desktop.
Save flowchartsman/d428f9a013937997bd52f798e6a9e531 to your computer and use it in GitHub Desktop.
v, ok := inter.(MyType)
if !ok {
return errors.New ("nope")
}
// becomes
switch v := inter.(type) {
case MyType:
// do MyType stuff with v
default:
return errors.New("nope")
// or maybe more ideally
return fmt.Errorf("Unexpected type %T", v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment