@@ -22,7 +22,9 @@ For a better understanding of the features provided by the package check the doc
2222
2323# Quick demo
2424
25- There's an example at ` examples/example1/example1.go ` that shows how to use the package. Here's the code for the example:
25+ There's an example at ` examples/example1/example1.go ` that shows how to use the package.
26+
27+ <details ><summary >Here's the code for the example:</summary >
2628
2729``` go
2830package main
@@ -78,11 +80,11 @@ func open() error {
7880func main () {
7981 if err := createTransaction (" tx_123456" ); err != nil {
8082 b , _ := json.MarshalIndent (err, " " , " " )
81- fmt.Println (" Error logged as a JSON structure using the JSON .MarshalIndent:" )
83+ fmt.Println (" Error logged as a JSON structure using the json .MarshalIndent:" )
8284 fmt.Printf (" %s \n " , b)
8385
8486 b, _ = json.Marshal (err)
85- fmt.Println (" \n Error logged as a JSON structure using the JSON .Marshal:" )
87+ fmt.Println (" \n Error logged as a JSON structure using the json .Marshal:" )
8688 fmt.Printf (" %s \n " , b)
8789
8890 fmt.Println (" \n Error logged using the s format specifier:" )
@@ -94,11 +96,13 @@ func main() {
9496}
9597```
9698
97- Here's the execution of the example:
99+ </details >
100+
101+ <details ><summary >Here's the execution of the example:</summary >
98102
99103```
100- $ go run examples/example1/example1.go
101- Error logged as a JSON structure using the JSON .MarshalIndent:
104+ $ go run examples/example1/example1.go
105+ Error logged as a JSON structure using the json .MarshalIndent:
102106[
103107 {
104108 "data": {
@@ -160,7 +164,7 @@ Error logged as a JSON structure using the JSON.MarshalIndent:
160164 }
161165]
162166
163- Error logged as a JSON structure using the JSON .Marshal:
167+ Error logged as a JSON structure using the json .Marshal:
164168[{"data":{"transactionId":"tx_123456","userId":"67890"},"message":"failed to complete the transaction on bank_123456","stack":["main.createTransaction @ /root/hack/errors/examples/example1/example1.go:13","main.main @ /root/hack/errors/examples/example1/example1.go:52","runtime/internal/atomic.(*Uint32).Load @ /root/go/version/go1.21.0/src/runtime/internal/atomic/types.go:194","runtime.goexit @ /root/go/version/go1.21.0/src/runtime/asm_amd64.s:1651"]},{"data":{"operation":"update","tableName":"transactions"},"message":"failed to update the database","stack":["main.updateDatabase @ /root/hack/errors/examples/example1/example1.go:24","main.createTransaction @ /root/hack/errors/examples/example1/example1.go:12","main.main @ /root/hack/errors/examples/example1/example1.go:52","runtime/internal/atomic.(*Uint32).Load @ /root/go/version/go1.21.0/src/runtime/internal/atomic/types.go:194","runtime.goexit @ /root/go/version/go1.21.0/src/runtime/asm_amd64.s:1651"]},{"data":{"server":"db-server-01","timeoutSeconds":30},"message":"connection timeout","stack":["main.createConnection @ /root/hack/errors/examples/example1/example1.go:35","main.updateDatabase @ /root/hack/errors/examples/example1/example1.go:23","main.createTransaction @ /root/hack/errors/examples/example1/example1.go:12","main.main @ /root/hack/errors/examples/example1/example1.go:52","runtime/internal/atomic.(*Uint32).Load @ /root/go/version/go1.21.0/src/runtime/internal/atomic/types.go:194","runtime.goexit @ /root/go/version/go1.21.0/src/runtime/asm_amd64.s:1651"]},{"data":{"network":"internal","severity":"high"},"message":"network instability detected","stack":["main.open @ /root/hack/errors/examples/example1/example1.go:45","main.createConnection @ /root/hack/errors/examples/example1/example1.go:34","main.updateDatabase @ /root/hack/errors/examples/example1/example1.go:23","main.createTransaction @ /root/hack/errors/examples/example1/example1.go:12","main.main @ /root/hack/errors/examples/example1/example1.go:52","runtime/internal/atomic.(*Uint32).Load @ /root/go/version/go1.21.0/src/runtime/internal/atomic/types.go:194","runtime.goexit @ /root/go/version/go1.21.0/src/runtime/asm_amd64.s:1651"]}]
165169
166170Error logged using the s format specifier:
@@ -170,8 +174,8 @@ Error logged using the +v format specifier:
170174message:
171175 "failed to complete the transaction on bank_123456"
172176data:
173- transactionId: tx_123456
174177 userId: 67890
178+ transactionId: tx_123456
175179stack:
176180 main.createTransaction @ /root/hack/errors/examples/example1/example1.go:13
177181 main.main @ /root/hack/errors/examples/example1/example1.go:52
@@ -216,4 +220,6 @@ cause:
216220 main.main @ /root/hack/errors/examples/example1/example1.go:52
217221 runtime/internal/atomic.(*Uint32).Load @ /root/go/version/go1.21.0/src/runtime/internal/atomic/types.go:194
218222 runtime.goexit @ /root/go/version/go1.21.0/src/runtime/asm_amd64.s:1651
219- ```
223+ ```
224+
225+ </details >
0 commit comments