errors

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2020 License: Apache-2.0 Imports: 0 Imported by: 13

README

Errors

A simple package for better errors handling. It assigns a string ID to each error for better parsing. It is also duck typed with Go error for interoperability.

package myPackage

import
import (
	"fmt"
	"github.com/a-novel/errors"
)

func main() {
	err := errors.New("uniq_id", "something happened")
	
	// ... 
	
	fmt.Print(err.Error()) // something happened
	fmt.Print(err.ID == "uniq_id") // true

	switch err.ID {
	case "uniq_id":
		// Do something.
    case "uniq_id_2":
        // Do something else.
	default:
        // Unknown/Unhandled error.
	}
}

License

Distributed under Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	ID      string `json:"id"`
	Message string `json:"message"`
}

func New

func New(id, message string) *Error

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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