errors.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package errors
  2. import (
  3. "fmt"
  4. )
  5. type AuthenticationError struct {
  6. AuthDetail interface{}
  7. }
  8. func NewAuthenticationError(detail interface{}) AuthenticationError {
  9. return AuthenticationError{
  10. AuthDetail: detail,
  11. }
  12. }
  13. func (err AuthenticationError) Error() string {
  14. return fmt.Sprintf("[Error 0x0001] Invalid auth %v", err.AuthDetail)
  15. }
  16. type ProtocolVersionError struct {
  17. Version int
  18. }
  19. func NewProtocolVersionError(version int) ProtocolVersionError {
  20. return ProtocolVersionError{
  21. Version: version,
  22. }
  23. }
  24. func (err ProtocolVersionError) Error() string {
  25. return fmt.Sprintf("[Error 0x0002] Invalid version %d", err.Version)
  26. }
  27. type CorruptedPacketError struct {
  28. }
  29. func NewCorruptedPacketError() CorruptedPacketError {
  30. return CorruptedPacketError{}
  31. }
  32. func (err CorruptedPacketError) Error() string {
  33. return "[Error 0x0003] Corrupted packet."
  34. }
  35. type IPFormatError struct {
  36. IP []byte
  37. }
  38. func NewIPFormatError(ip []byte) IPFormatError {
  39. return IPFormatError{
  40. IP: ip,
  41. }
  42. }
  43. func (err IPFormatError) Error() string {
  44. return fmt.Sprintf("[Error 0x0004] Invalid IP %v", err.IP)
  45. }