foldertype.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (C) 2016 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package config
  7. type FolderType int32
  8. const (
  9. FolderTypeSendReceive FolderType = 0
  10. FolderTypeSendOnly FolderType = 1
  11. FolderTypeReceiveOnly FolderType = 2
  12. FolderTypeReceiveEncrypted FolderType = 3
  13. )
  14. func (t FolderType) String() string {
  15. switch t {
  16. case FolderTypeSendReceive:
  17. return "sendreceive"
  18. case FolderTypeSendOnly:
  19. return "sendonly"
  20. case FolderTypeReceiveOnly:
  21. return "receiveonly"
  22. case FolderTypeReceiveEncrypted:
  23. return "receiveencrypted"
  24. default:
  25. return "unknown"
  26. }
  27. }
  28. func (t FolderType) MarshalText() ([]byte, error) {
  29. return []byte(t.String()), nil
  30. }
  31. func (t *FolderType) UnmarshalText(bs []byte) error {
  32. switch string(bs) {
  33. case "readwrite", "sendreceive":
  34. *t = FolderTypeSendReceive
  35. case "readonly", "sendonly":
  36. *t = FolderTypeSendOnly
  37. case "receiveonly":
  38. *t = FolderTypeReceiveOnly
  39. case "receiveencrypted":
  40. *t = FolderTypeReceiveEncrypted
  41. default:
  42. *t = FolderTypeSendReceive
  43. }
  44. return nil
  45. }