example_test.go 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package ecode_test
  2. import (
  3. "fmt"
  4. "go-common/library/ecode"
  5. "github.com/pkg/errors"
  6. )
  7. func Example_ecode_Message() {
  8. _ = ecode.NotModified.Message()
  9. }
  10. func Example_ecode_Code() {
  11. _ = ecode.NotModified.Code()
  12. }
  13. func Example_ecode_Error() {
  14. _ = ecode.NotModified.Error()
  15. }
  16. func ExampleCause() {
  17. err := errors.WithStack(ecode.AccessDenied)
  18. ecode.Cause(err)
  19. }
  20. func ExampleInt() {
  21. err := ecode.Int(500)
  22. fmt.Println(err)
  23. // Output:
  24. // 500
  25. }
  26. func ExampleString() {
  27. ecode.String("500")
  28. }
  29. // ExampleStack package error with stack.
  30. func Example() {
  31. err := errors.New("dao error")
  32. errors.Wrap(err, "some message")
  33. // package ecode with stack.
  34. errCode := ecode.AccessDenied
  35. err = errors.Wrap(errCode, "some message")
  36. //get ecode from package error
  37. code := errors.Cause(err).(ecode.Codes)
  38. fmt.Printf("%d: %s\n", code.Code(), code.Message())
  39. }