must

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 0 Imported by: 0

README

Example

package main

import (
	"errors"
	"github.com/aktivgo-gopkg/must"
	"log"
)

func checkEqual(a, b int) error {
	if a != b {
		return errors.New("a not equal b")
	}

	return nil
}

func sub(a, b int) (int, error) {
	if a < b {
		return 0, errors.New("a less than b")
	}

	return a - b, nil
}

func main() {
	must.All(checkEqual(1, 1)) // ok
	must.All(checkEqual(1, 2)) // panic

	log.Println(must.Do(sub(2, 1))) // ok, 1
	log.Println(must.Do(sub(1, 2))) // panic
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All added in v0.0.4

func All(args ...any)

All causes panic if the last argument is an error and is not nil

func Do

func Do[T any](result T, err error) T

Do causes panic if the error is not nil otherwise returns the result

Types

This section is empty.

Jump to

Keyboard shortcuts

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