mustcheck

package module
Version: v0.0.0-...-559ed3c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2018 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(err error)

Check compares err with nil and panics.

In lots of cases, it's only necessary to log the error in fail fast. Copy-paste leads to errors and untested code (someone may forget to return, other may use log incorrectly). By using panic you can implement logging in one place (recovery) and also have a stack trace. If you code really has the second path or needs custom error handling just don't use it.

Example:

f, err := os.Create(path)
check(err)

¯\_(ツ)_/¯

func Must

func Must(val interface{}, err error) interface{}

Must ensures what returned err is nil and returns the result, panics otherwise.

This is useful for creating structures where you don't need explicit error handling and prefer to fail fast.

Example:

return Must(strconv.Atoi(str)).(int)

Note what you need to cast an interface to proper type.

(╯°□°)╯︵ ┻━┻

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL