check

package module
v0.0.0-...-68a0407 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: MIT Imports: 1 Imported by: 0

README

Check

GoDoc

Check multiple errors/functions

If you want to check some functions currently, and lazy to write some code, you can use this lib.

This lib will check the checkpoints you provided, run then in currency, and return the first error or false if found. Otherwise, return true or nil error, means all checkpoints are passed.

Get this package and run the example:

go get github.com/wrfly/check

# generate errors or false randomly
go run $GOPATH/src/github.com/wrfly/check/example/main.go

# no error or false
go run $GOPATH/src/github.com/wrfly/check/example/main.go -ne

Go test result

go test -v --race --cover .
=== RUN   TestCheck
=== RUN   TestCheck/pass
=== RUN   TestCheck/not_pass
=== RUN   TestCheck/error
=== RUN   TestCheck/no_error
=== RUN   TestCheck/not_pass_with_all_cancel
=== RUN   TestCheck/error_with_all_cancel
=== RUN   TestCheck/not_pass_with_some_cancel
=== RUN   TestCheck/error_with_some_cancel
=== RUN   TestCheck/no_check_points
--- PASS: TestCheck (0.27s)
    --- PASS: TestCheck/pass (0.09s)
    --- PASS: TestCheck/not_pass (0.01s)
    --- PASS: TestCheck/error (0.10s)
    --- PASS: TestCheck/no_error (0.00s)
    --- PASS: TestCheck/not_pass_with_all_cancel (0.00s)
    --- PASS: TestCheck/error_with_all_cancel (0.00s)
    --- PASS: TestCheck/not_pass_with_some_cancel (0.00s)
    --- PASS: TestCheck/error_with_some_cancel (0.05s)
    --- PASS: TestCheck/no_check_points (0.00s)
PASS
coverage: 100.0% of statements
ok      github.com/wrfly/check  1.281s  coverage: 100.0% of statements

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoError

func NoError(ctx context.Context, checkPoints []FuncWithErr) error

NoError returns the first error it got, if all passed, returns nil

func Passed

func Passed(ctx context.Context, checkPoints []Func) bool

Passed returns true if all check points passed, otherwise, returns false

Types

type Func

type Func func() bool

Func is the check function that only returns true or false

type FuncWithErr

type FuncWithErr func() error

FuncWithErr returns error if any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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