calm

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 2 Imported by: 1

README

Calm

Dual mode error and result handling library for Golang 1.20+

Documentation

Index

Constants

View Source
const (
	EConfig   = 1
	ERequest  = 2
	EDenied   = 3
	EInternal = 4
)

Variables

View Source
var (
	AsEConfig   = func(err Error) { ThrowNested(EConfig, err) }
	AsERequest  = func(err Error) { ThrowNested(ERequest, err) }
	AsEDenied   = func(err Error) { ThrowNested(EDenied, err) }
	AsEInternal = func(err Error) { ThrowNested(EInternal, err) }
)

Functions

func Throw

func Throw(err error)

func ThrowNested

func ThrowNested(err int, nested error)

func ThrowTagged

func ThrowTagged(err int, message string)

func Unreachable

func Unreachable[T any]() (ret T)

Types

type Error

type Error interface {
	Type() int
	error
}

func NestedError

func NestedError(err int, nested error) Error

func TaggedError

func TaggedError(err int, message string) Error

type Result

type Result struct {
	// contains filtered or unexported fields
}

func Assert

func Assert(condition bool, message ...string) Result

func ErrResult

func ErrResult(err error) Result

func Run

func Run(exec func()) (ret Result)

func ValResult

func ValResult() Result

func Wrap

func Wrap(err error) Result

func (Result) Dump

func (c Result) Dump() Error

func (Result) Fold

func (c Result) Fold(onError func(Error))

func (Result) Get

func (c Result) Get()

func (Result) Unwrap

func (c Result) Unwrap(onError func(Error))

type ResultT

type ResultT[T any] struct {
	Result
	// contains filtered or unexported fields
}

func ErrResultT

func ErrResultT[T any](err error) ResultT[T]

func RunT

func RunT[T any](exec func() T) (ret ResultT[T])

func ValResultT

func ValResultT[T any](v T) ResultT[T]

func WrapT

func WrapT[T any](v T, err error) ResultT[T]

func (ResultT[T]) Dump

func (c ResultT[T]) Dump() (T, Error)

func (ResultT[T]) Fold

func (c ResultT[T]) Fold(onError func(Error) T) T

func (ResultT[T]) Get

func (c ResultT[T]) Get() T

func (ResultT[T]) Unwrap

func (c ResultT[T]) Unwrap(onError func(Error)) T

Jump to

Keyboard shortcuts

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