Skip to content

Instantly share code, notes, and snippets.

@kardolus
Created October 10, 2019 16:08
Show Gist options
  • Save kardolus/77961504240e5e67dfb554b14a810b83 to your computer and use it in GitHub Desktop.
Save kardolus/77961504240e5e67dfb554b14a810b83 to your computer and use it in GitHub Desktop.
Common error handling pattern
package main
import (
"fmt"
"os"
)
func main() {
exit(run())
}
func exit(err error) {
if err == nil {
os.Exit(0)
}
fmt.Printf("%s", err)
os.Exit(1)
}
func run() error {
fmt.Println("Hello world")
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment