mirror of
https://gitee.com/johng/gf.git
synced 2024-11-29 18:57:44 +08:00
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
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:
parent
138dea0f3a
commit
bcfcda793c
@ -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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user