chore(errors/gerror): add examples (#3927)
Some checks are pending
GoFrame Main CI / code-test (1.20, 386) (push) Waiting to run
GoFrame Main CI / code-test (1.20, amd64) (push) Waiting to run
GoFrame Main CI / code-test (1.21, 386) (push) Waiting to run
GoFrame Main CI / code-test (1.21, amd64) (push) Waiting to run
GoFrame Main CI / code-test (1.22, 386) (push) Waiting to run
GoFrame Main CI / code-test (1.22, amd64) (push) Waiting to run
GoFrame Main CI / code-test (1.23, 386) (push) Waiting to run
GoFrame Main CI / code-test (1.23, amd64) (push) Waiting to run
GoFrame Sub CI / code-test (1.20, 386) (push) Waiting to run
GoFrame Sub CI / code-test (1.20, amd64) (push) Waiting to run
GoFrame Sub CI / code-test (1.21, 386) (push) Waiting to run
GoFrame Sub CI / code-test (1.21, amd64) (push) Waiting to run
GoFrame Sub CI / code-test (1.22, 386) (push) Waiting to run
GoFrame Sub CI / code-test (1.22, amd64) (push) Waiting to run
GoFrame Sub CI / code-test (1.23, 386) (push) Waiting to run
GoFrame Sub CI / code-test (1.23, amd64) (push) Waiting to run
Sync to Gitee / Run (push) Waiting to run
GolangCI-Lint / golangci-lint (1.20) (push) Waiting to run
GolangCI-Lint / golangci-lint (1.21.4) (push) Waiting to run
GolangCI-Lint / golangci-lint (1.22) (push) Waiting to run
GolangCI-Lint / golangci-lint (1.23) (push) Waiting to run
Sonarcloud Scan / Scorecards analysis (push) Waiting to run

This commit is contained in:
John Guo 2024-11-16 18:14:40 +08:00 committed by GitHub
parent 138dea0f3a
commit bcfcda793c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -82,3 +82,25 @@ func ExampleIs() {
// true // true
// false // 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
}