Categorygithub.com/jerbe/go-errors
modulepackage
1.0.1
Repository: https://github.com/jerbe/go-errors.git
Documentation: pkg.go.dev

# README

GO-Errors 一个简单易用的golang错误包

使用方法

import (
    "errors"
    "fmt"
    "testing"
)


var T = New("this is test")

func TestWrap(t *testing.T) {
    var e error
    e = errors.New("Error One")
    e = T.Wrap(e)
    e = e.(*Error).Wrap(e)
    e = Wrap(e)
    e = Wrap(e)
    e = Wrap(e)
    fmt.Printf("%+v\n", e)
    fmt.Printf("%s\n", e.Error())
    
    e2 := New("Error Two")
    e = e.(*Error).Wrap(e2)
    e = Wrap(e)
    e = Wrap(e)
    fmt.Printf("%+v", e)
    fmt.Printf("%s\n", e.Error())
}


//OUTPUT
[github.com/jerbe/go-errors.TestWrap]:/Users/Jerbe/Workshop/Study/github.com/jerbe/go-errors/error_test.go:24
[github.com/jerbe/go-errors.TestWrap]:/Users/Jerbe/Workshop/Study/github.com/jerbe/go-errors/error_test.go:23
[github.com/jerbe/go-errors.TestWrap]:/Users/Jerbe/Workshop/Study/github.com/jerbe/go-errors/error_test.go:22
[github.com/jerbe/go-errors.TestWrap]:/Users/Jerbe/Workshop/Study/github.com/jerbe/go-errors/error_test.go:21 => this is test
[github.com/jerbe/go-errors.TestWrap]:/Users/Jerbe/Workshop/Study/github.com/jerbe/go-errors/error_test.go:20 => this is test
Error One
Error One
[github.com/jerbe/go-errors.TestWrap]:/Users/Jerbe/Workshop/Study/github.com/jerbe/go-errors/error_test.go:31
[github.com/jerbe/go-errors.TestWrap]:/Users/Jerbe/Workshop/Study/github.com/jerbe/go-errors/error_test.go:30
[github.com/jerbe/go-errors.TestWrap]:/Users/Jerbe/Workshop/Study/github.com/jerbe/go-errors/error_test.go:29
Error Two
Error Two

# Functions

As 查找 err 链中与 target 匹配的第一个错误,如果找到,则将 target 设置为该错误值并返回 true。否则,它将返回 false。.
Is 报告错误链中的任何错误是否与目标匹配。.
IsIn 报告错误链中的任何错误是否与目标组中其中一个目标匹配。.
New 生成错误.
NewWithCaller 生成带caller的错误.
Unwrap 如果 err 的类型包含返回错误的解包方法,则返回在 err 上调用解包方法的结果。否则,解包将返回 nil。.
Wrap 包裹err并返回一个新的error.

# Structs

Error 栈错误.