check

package
v0.0.0-...-862e07f Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: MIT Imports: 2 Imported by: 0

README

Generic error-checking for go

GoDoc

package main

import (
	"fmt"
	"git.ppdv.net/go/util/check"
	"errors"
)

func demoOk(a string, b int) (int, error) {
	return b, nil
}

func demoError(b int) (int, error) {
	return b, errors.New("An error")
}

func main() {
	var i int
	check.Must(demoOk("test", 1234)).SetVars(&i)
	fmt.Println(i)
	check.Must(demoError(1234))
}

Documentation

Overview

Package check provides functions for working with errors and return-values. Provided functions can eliminate boring condition

if err != nil

Package never returns any errors and calls panic() on error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Must2

func Must2(arg0, arg1 interface{}) interface{}

calls Must(arg0, arg1), returns arg0, useful for one-line type-assertion

func Panic

func Panic(condition interface{}, args ...interface{})

calls panic() if condition is non-nil error, true bool or any other type. optional arguments, if given, must start from string and will be passed to fmt.Sprintf

Types

type Values

type Values []interface{}

represents return value(s) obtained via Must()

func Must

func Must(args ...interface{}) Values

calls Panic() on last arg, returns remaining does nothing if no args given, returns nil if less than 2 args

func (Values) SetVar

func (v Values) SetVar(offset int, target interface{})

sets target to value of v[offset] using reflect. target must be a pointer and have compatible type

func (Values) SetVars

func (v Values) SetVars(targets ...interface{})

sets target vars to values of v using reflect. targets must be a pointer of compatible type or nil, targets count must be equal to len(v).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL