Skip to content

Commit

Permalink
doc: example
Browse files Browse the repository at this point in the history
  • Loading branch information
DenChenn committed Sep 5, 2023
1 parent 4d7a05e commit 6c6a932
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ It generate typed errors and manage them in centralized way, which reduce the de
go run github.com/DenChenn/blunder gen --complete=true
```

## Usage [WIP]
## Usage
Suppose your errors in `blunder.yaml` are defined like this:
```yaml
details:
Expand All @@ -46,4 +46,31 @@ details:
#...
- code: Err3
#...
```
```

Your error will be generated in given path like this:
```
<your_dir_path>/
generated/
alayer/
errors.go
blayer/
errors.go
blunder.yaml
```

Which can be import into your code like this:
```go
if err != nil {
if errors.As(err, &alayer.Err1) {
//...
}
}
```

Or you can wrap your error like this:
```go
if errors.As(err, &pgx.ErrNoRows) {
return &alayer.Err1.Wrap(err)
}
```

0 comments on commit 6c6a932

Please sign in to comment.