Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(errors/gerror): add examples #3927

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading