safe

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: MIT Imports: 2 Imported by: 2

README

go-safe

test codecov GoDoc Go Report Card

Provides functionality to help you execute methods safely.

Installation

go get -u github.com/kenkyu392/go-safe

Usage

package main

import (
	"log"

	"github.com/kenkyu392/go-safe"
)

func main() {
	// The panic that occurs in the function is automatically handled as an error.
	if err := safe.Do(func() error {
		// Do something...
		return nil
	}); err != nil {
		log.Fatal(err)
	}
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(fn func() error) (err error)

Do solves panic automatically, converts it to an error and returns it.

func Func

func Func(fn func() error) func() error

Func returns the method to be executed safely.

Types

This section is empty.

Jump to

Keyboard shortcuts

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