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 ReturnT ¶
ReturnT is a variant of Return() for use in unit tests. Instead of exiting the program, any non-nil errors are reported with t.Fatal(). For example:
buf := must.ReturnT(os.ReadFile("config.ini"))(t)
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.