globals.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Rufs - Remote Union File System
  3. *
  4. * Copyright 2017 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package node
  11. import (
  12. "errors"
  13. "fmt"
  14. "log"
  15. )
  16. // Logging
  17. // =======
  18. /*
  19. Logger is a function which processes log messages
  20. */
  21. type Logger func(v ...interface{})
  22. /*
  23. LogInfo is called if an info message is logged
  24. */
  25. var LogInfo = Logger(log.Print)
  26. /*
  27. LogDebug is called if a debug message is logged
  28. (by default disabled)
  29. */
  30. var LogDebug = Logger(LogNull)
  31. /*
  32. LogNull is a discarding logger to be used for disabling loggers
  33. */
  34. var LogNull = func(v ...interface{}) {
  35. }
  36. // Errors
  37. // ======
  38. /*
  39. Error is a network related error
  40. */
  41. type Error struct {
  42. Type error // Error type (to be used for equal checks)
  43. Detail string // Details of this error
  44. IsNotExist bool // Error is file or directory does not exist
  45. }
  46. /*
  47. Error returns a human-readable string representation of this error.
  48. */
  49. func (ge *Error) Error() string {
  50. if ge.Detail != "" {
  51. return fmt.Sprintf("RufsError: %v (%v)", ge.Type, ge.Detail)
  52. }
  53. return fmt.Sprintf("RufsError: %v", ge.Type)
  54. }
  55. /*
  56. Network related error types
  57. */
  58. var (
  59. ErrNodeComm = errors.New("Network error")
  60. ErrRemoteAction = errors.New("Remote error")
  61. ErrUnknownTarget = errors.New("Unknown target node")
  62. ErrUntrustedTarget = errors.New("Unexpected SSL certificate from target node")
  63. ErrInvalidToken = errors.New("Invalid node token")
  64. )