gcode_local.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gcode
  7. import "fmt"
  8. // localCode is an implementer for interface Code for internal usage only.
  9. type localCode struct {
  10. code int // Error code, usually an integer.
  11. message string // Brief message for this error code.
  12. detail interface{} // As type of interface, it is mainly designed as an extension field for error code.
  13. }
  14. // Code returns the integer number of current error code.
  15. func (c localCode) Code() int {
  16. return c.code
  17. }
  18. // Message returns the brief message for current error code.
  19. func (c localCode) Message() string {
  20. return c.message
  21. }
  22. // Detail returns the detailed information of current error code,
  23. // which is mainly designed as an extension field for error code.
  24. func (c localCode) Detail() interface{} {
  25. return c.detail
  26. }
  27. // String returns current error code as a string.
  28. func (c localCode) String() string {
  29. if c.detail != nil {
  30. return fmt.Sprintf(`%d:%s %v`, c.code, c.message, c.detail)
  31. }
  32. if c.message != "" {
  33. return fmt.Sprintf(`%d:%s`, c.code, c.message)
  34. }
  35. return fmt.Sprintf(`%d`, c.code)
  36. }