Thanks to visit codestin.com
Credit goes to github.com

Skip to content

thombashi/eoe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eoe

Provide a simple function to exit the program with an error message on errors in Go.

Go Reference Go Report Card CI CodeQL

Installation

go get -u github.com/thombashi/eoe

Usage

package main

import (
    "github.com/thombashi/eoe"
)

func successFunc() error {
	return nil
}

func errrorFunc() error {
	return errors.New("an error occurred")
}

func main() {
	var err error
	logger := slog.Default()
	params := eoe.NewParams().WithLogger(logger)

	// should not exit if the error is nil
	err = successFunc()
	eoe.ExitOnError(err, params.WithMessage("should not exit"))

	// should exit if the error is not nil
	err = errrorFunc()
	eoe.ExitOnError(err, params.WithMessage("should exit with an error message"))
}

About

Provide a simple function to exit the program with an error message on errors in Go.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published