Documentation
¶
Overview ¶
Package must contains convenience functions for quickly exiting on fatal errors without the need for excessive "if err != nil".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Return ¶
Return is like Succeed(), except that it propagates a result value on success. This can be chained with functions returning a pair of result value and error if errors are considered fatal. For example, the following:
buf, err := os.ReadFile("config.ini") if err != nil { logg.Fatal(err.Error()) }
can be shortened to:
buf := must.Return(os.ReadFile("config.ini"))
func Succeed ¶
func Succeed(err error)
Succeed logs a fatal error and terminates the program if the given error is non-nil. For example, the following:
fileContents := []byte("loglevel = info") err := os.WriteFile("config.ini", fileContents, 0666) if err != nil { logg.Fatal(err.Error()) }
can be shortened to:
fileContents := []byte("loglevel = info") must.Succeed(os.WriteFile("config.ini", fileContents, 0666))
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.