Discover Packages
github.com/a-novel/errors
package
module
Version:
v1.0.0
Opens a new window with list of versions in this module.
Published: Dec 26, 2020
License: Apache-2.0
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 13
Opens a new window with list of known importers.
README
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
Expand ▾
Collapse ▴
Documentation
¶
type Error struct {
ID string `json:"id"`
Message string `json:"message"`
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.