gland

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2021 License: MIT Imports: 4 Imported by: 0

README

Gland feedback

It's lovely to hear your suggestion,share your thoughts hear: https://github.com/sinngae/gland/issues

Thank you!

Install

go get github.com/sinngae/gland

What is Gland

Gland is an error-handling solution for Go applications. It supports:

  • error handling
  • error tracing
  • return code handling

Gland want be thought of as a complete API for error handing.

Binding error With Values

    err := fmt.Errorf("this is cause")

    err = gland.WithMessage(err, "this is msg")
    // err.Error() -> {"message":"this is msg", "err":"this is cause"}

    err = gland.RetCode(err, 404)
    // err.Error() -> {"retcode":404, "err":"this is cause"}

    rcMsg := NewRetCodeMsg(404, "this is msg")
    err = gland.WithRetCodeMessage(err, rcMsg)
    // err = gland.WithRetCodeMessagef(err, 404, "this is msg")
    // err.Error() -> {"retcode":404, "message":"this is msg", "err":"this is cause"}

    err = gland.WithStack(err) 
    /* err.Error() will be:
        {"stack":
        "/Users/ziqiangren/gitwork/gland/internal/stack.go:19 (0x10fb1fd)
        /Users/ziqiangren/gitwork/gland/stack.go:22 (0x10fb1f1)
        /Users/ziqiangren/gitwork/gland/stack.go:17 (0x10fb133)
        /Users/ziqiangren/gitwork/gland/stack_test.go:9 (0x10fc2d1)
        /usr/local/Cellar/go@1.13/1.13.15/libexec/src/runtime/proc.go:5228 (0x103a189)
        /usr/local/Cellar/go@1.13/1.13.15/libexec/src/runtime/proc.go:5223 (0x103a156)
        /usr/local/Cellar/go@1.13/1.13.15/libexec/src/runtime/proc.go:190 (0x102df61)
        /usr/local/Cellar/go@1.13/1.13.15/libexec/src/runtime/asm_amd64.s:1357 (0x1059610)
        ", "sum":"d172cdbeb85c21276423d3ede5dfd046", "err":"this is cause"}
    */

Roadmap

  • 0.1.5 add stack & hash sum

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RetCodeSuccess int = 0
	MsgSuccess         = "success"
	CodeMsgSuccess     = NewRetCodeMsg(RetCodeSuccess, MsgSuccess)

	RetCodeFailure int = 1
	MsgFailure         = "failure"
	CodeMsgFailure     = NewRetCodeMsg(RetCodeFailure, MsgFailure)

	RetCodeUnknown int = 2
	MsgUnknown         = "unknown"
	CodeMsgUnknown     = NewRetCodeMsg(RetCodeUnknown, MsgUnknown)
)

Functions

func Cause

func Cause(err error) error

func Is

func Is(err error, retCode int) bool

func JsonStr

func JsonStr(err error) string

func Message

func Message(err error) string

func NewRetCodeMsg

func NewRetCodeMsg(retcode int, msg string) *withRetCodeMessage

func NewStack

func NewStack() *internal.MyStack

func RetCode

func RetCode(err error) int

func RetCodeMsg

func RetCodeMsg(err error) *withRetCodeMessage

func Stack

func Stack(err error) *internal.MyStack

func UnSafeInitCodeSet

func UnSafeInitCodeSet()

func WithMessage

func WithMessage(err error, msg string) error

func WithRetCode

func WithRetCode(err error, retCode int) error

func WithRetCodeMessage

func WithRetCodeMessage(err error, rm *withRetCodeMessage) error

func WithRetCodeMessagef

func WithRetCodeMessagef(err error, retCode int, format string, args ...interface{}) error

func WithStack

func WithStack(err error) error

Types

This section is empty.

Directories

Path Synopsis
pkg
sample module

Jump to

Keyboard shortcuts

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