chore(errors/gerror): add examples (#3927)

This commit is contained in:
John Guo
2024-11-16 18:14:40 +08:00
committed by GitHub
parent 138dea0f3a
commit bcfcda793c

View File

@ -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
}