From bcfcda793c68a8ce0fccf63dda01f404d33b39d5 Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 16 Nov 2024 18:14:40 +0800 Subject: [PATCH] chore(errors/gerror): add examples (#3927) --- errors/gerror/gerror_z_example_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/errors/gerror/gerror_z_example_test.go b/errors/gerror/gerror_z_example_test.go index 6d828abbd..a0af3762f 100644 --- a/errors/gerror/gerror_z_example_test.go +++ b/errors/gerror/gerror_z_example_test.go @@ -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 +}