Skip to content

Commit

Permalink
bump to v2.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Dec 6, 2020
1 parent 6e139db commit ce3bb90
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,43 @@ func b(){

Try it at: <https://play.golang.org/p/Y2uThZHAvK1>

### Builtin Codes

The builtin Codes are errors, such as `OK`, `Canceled`, `Unknown`, `InvalidArgument`, `DeadlineExceeded`, `NotFound`, `AlreadyExists`, etc..

```go
// using the pre-defined error code
// Uses a Code as an error
var err error = errors.OK
var err2 error = errors.InvalidArgument
fmt.Println("error is: %v", err2)

// Uses a Code as enh-error (hedzr/errors)
err := InvalidArgument.New("wrong").Attach(io.ErrShortWrite)
```

### Customized Codes

```go
// customizing the error code
const MyCode001 Code=1001
const MyCode001 errors.Code=1001

// and register its name
// and register the name of MyCode001
MyCode001.Register("MyCode001")
// and use the error code

// and use it as a builtin Code
fmt.Println("error is: %v", MyCode001)
err := MyCode001.New("wrong 001: no config file")
```

### Error Template: formatting the coded-error late


```go
errTmpl1001 := BUG1001.NewTemplate("something is wrong, %v")
err4 := errTmpl1001.FormatNew("unsatisfied conditions").Attach(io.ShortBuffer)
fmt.Println(err4)
fmt.Printf("%+v\n", err4)
const BUG1001 errors.Code=1001
errTmpl1001 := BUG1001.NewTemplate("something is wrong, %v")
err4 := errTmpl1001.FormatNew("unsatisfied conditions").Attach(io.ShortBuffer)
fmt.Println(err4)
fmt.Printf("%+v\n", err4)
```


Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
// AppName const
AppName = "errors"
// Version const
Version = "2.1.1"
Version = "2.1.3"
// VersionInt const
VersionInt = 0x020101
VersionInt = 0x020103
)

0 comments on commit ce3bb90

Please sign in to comment.