errgo

go.dev reference GitHub go.mod Go version GitHub tag (latest SemVer) GitHub license

errgo generates a custom interface for error errgo.ErrGo with code and message as a standard.

Getting started

Installation

You can use the go get method:

go get github.com/dalikewara/errgo

Usage

type ErrGo interface {
    GetError() error
    GetCode() string
    GetMessage() string
    GetHttpStatus() int
}

Generate new error

err := errgo.New("01", "data not found")

fmt.Println(err.GetCode()) // 01
fmt.Println(err.GetMessage()) // data not found
fmt.Println(err.GetError().Error()) // 01||data not found

Generate new error with http status

err := errgo.NewWithHttpStatus("01", "data not found", 200)

fmt.Println(err.GetCode()) // 01
fmt.Println(err.GetMessage()) // data not found
fmt.Println(err.GetHttpStatus()) // 200
fmt.Println(err.GetError().Error()) // 01||data not found

Release

Changelog

Read at CHANGELOG.md

Credits

Copyright © 2022 Dali Kewara

License

MIT License

GitHub

View Github