gerror

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 4 Imported by: 12

README

Gerror for error handling

Go Report Card GoDoc GitHub license

⚙️ Installation

go get -u github.com/ysfgrl/gerror

⚡️ Examples


func NewUserError() error {
    return errors.New("NewUserError")
}
func NewUserError2() *Error {
    if err := NewUserError(); err != nil {
        return GetError(err)
    }
    return nil
}

func main() {
    err := NewUserError()
    if err != nil {
        gerr := GetError(err)
        gerr.PrintConsole()
    }
    gerr := NewUserError2()
    if gerr != nil {
        gerr.PrintConsole()
    } else {
        t.Fatalf("%v", "Error TestGError")
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitErrorHandler added in v0.0.2

func InitErrorHandler(handler ErrorHandler)

Types

type Error

type Error struct {
	File     string `json:"file"`
	Function string `json:"function"`
	Detail   any    `json:"detail"`
	Line     int    `json:"line"`
	Code     string `json:"code"`
	Err      error  `json:"-"`
}

func GetError

func GetError(err error) *Error

func GetErrorCode added in v0.0.2

func GetErrorCode(err error, code string) *Error

func UserError

func UserError(msg string, code string) *Error

func (*Error) PrintConsole

func (e *Error) PrintConsole()

func (*Error) ToJsonByte

func (e *Error) ToJsonByte() []byte

func (*Error) ToMap

func (e *Error) ToMap() map[string]interface{}

type ErrorHandler added in v0.0.2

type ErrorHandler = func(error Error)

type Pool added in v0.0.2

type Pool struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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