Skip to content

Instantly share code, notes, and snippets.

@mkock
Last active October 3, 2021 09:26
Show Gist options
  • Select an option

  • Save mkock/75cd677c669865875fa3ff8f4a9831a3 to your computer and use it in GitHub Desktop.

Select an option

Save mkock/75cd677c669865875fa3ff8f4a9831a3 to your computer and use it in GitHub Desktop.
type myError struct{}
func (m *myError) Error() string {
return "failure"
}
func doSomething() (string, *myError) {
return "", nil
}
func main() {
var result string
var err error
if result, err = doSomething(); err != nil {
fmt.Println("We have received an error!") // Prints "We have received an error!"
} else {
fmt.Println(result) // Is never called.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment