errors.go 417 B

1234567891011121314151617181920212223242526272829
  1. package common
  2. type ErrorCode int
  3. const (
  4. GENERAL_ERR ErrorCode = iota
  5. NOT_FOUND
  6. )
  7. type Error struct {
  8. msg string
  9. code ErrorCode
  10. }
  11. func NewError(message string) *Error {
  12. return &Error{message, GENERAL_ERR}
  13. }
  14. func NewErrorWithCode(code ErrorCode, message string) *Error {
  15. return &Error{message, code}
  16. }
  17. func (e *Error) Error() string {
  18. return e.msg
  19. }
  20. func (e *Error) Code() ErrorCode {
  21. return e.code
  22. }