forked from abyssparanoia/goerr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use kv object instead of array for values encoding (#2)
* Migrate to reproio * Use kv object instead of array for values encoding * remove tag
- Loading branch information
Showing
2 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"github.com/reproio/goerr" | ||
"go.uber.org/zap" | ||
"log" | ||
) | ||
|
||
type Nested struct { | ||
NestedData string | ||
} | ||
type MyStruct struct { | ||
Num int | ||
Str string | ||
Nested *Nested | ||
} | ||
|
||
func main() { | ||
logger, _ := zap.NewDevelopment() | ||
defer logger.Sync() | ||
|
||
st := MyStruct{ | ||
Num: 1, | ||
Str: "str", | ||
Nested: &Nested{ | ||
NestedData: "nested", | ||
}, | ||
} | ||
|
||
err := goerr.Wrap(errors.New("some error")).WithValue("key", "value").WithValue("num_key", 1).WithValue("struct", st) | ||
|
||
if goErr := goerr.Unwrap(err); goErr != nil { | ||
log.Printf("%s\n", goErr.LogValue()) | ||
} | ||
|
||
logger.Error("something happening", zap.Object("error", err)) | ||
} |