Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Don't use os.Exit (or logging.Fatal) anywhere except the main function - this stops any 'defer' statements from running and also prints no message when it exits, which can cause confusion when trying to debug why a program suddenly stopped. If something has failed in such a way that it can't recover, panic instead. If nothing else needs to happen, just return from the function you are in (and handle this case further up).
  • If you are returning an error from another package (or a standard library function), wrap it with errors.Wrap from github.com/pkg/errors which will add context to the error to make it easier to understand where it comes from. If you are creating a new error, use errors.New (or errors.Errorf instead of fmt.Errorf) from the same library which provide the same utility.

...