globals.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package manager
  11. import (
  12. "errors"
  13. "fmt"
  14. "log"
  15. )
  16. // Logging
  17. // =======
  18. /*
  19. Logger is a function which processes log messages from the cluster
  20. */
  21. type Logger func(v ...interface{})
  22. /*
  23. LogInfo is called if an info message is logged in the cluster code
  24. */
  25. var LogInfo = Logger(log.Print)
  26. /*
  27. LogDebug is called if a debug message is logged in the cluster code
  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 cluster 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. }
  45. /*
  46. Error returns a human-readable string representation of this error.
  47. */
  48. func (ge *Error) Error() string {
  49. if ge.Detail != "" {
  50. return fmt.Sprintf("ClusterError: %v (%v)", ge.Type, ge.Detail)
  51. }
  52. return fmt.Sprintf("ClusterError: %v", ge.Type)
  53. }
  54. /*
  55. Cluster related error types
  56. */
  57. var (
  58. ErrMemberComm = errors.New("Network error")
  59. ErrMemberError = errors.New("Member error")
  60. ErrClusterConfig = errors.New("Cluster configuration error")
  61. ErrClusterState = errors.New("Cluster state error")
  62. ErrUnknownPeer = errors.New("Unknown peer member")
  63. ErrUnknownTarget = errors.New("Unknown target member")
  64. ErrInvalidToken = errors.New("Invalid member token")
  65. ErrNotMember = errors.New("Client is not a cluster member")
  66. ErrLockTaken = errors.New("Requested lock is already taken")
  67. ErrLockNotOwned = errors.New("Requested lock not owned")
  68. )