Skip to content

Commit

Permalink
chore(errors/gerror): add examples (#3927)
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn authored Nov 16, 2024
1 parent 138dea0 commit bcfcda7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions errors/gerror/gerror_z_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,25 @@ func ExampleIs() {
// true
// false
}

func ExampleCode() {
err1 := gerror.NewCode(gcode.CodeInternalError, "permission denied")
err2 := gerror.Wrap(err1, "operation failed")
fmt.Println(gerror.Code(err1))
fmt.Println(gerror.Code(err2))

// Output:
// 50:Internal Error
// 50:Internal Error
}

func ExampleHasCode() {
err1 := gerror.NewCode(gcode.CodeInternalError, "permission denied")
err2 := gerror.Wrap(err1, "operation failed")
fmt.Println(gerror.HasCode(err1, gcode.CodeOK))
fmt.Println(gerror.HasCode(err2, gcode.CodeInternalError))

// Output:
// false
// true
}

0 comments on commit bcfcda7

Please sign in to comment.