foldertype.go 1012 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. func (t FolderType) String() string {
  8. switch t {
  9. case FolderTypeSendReceive:
  10. return "sendreceive"
  11. case FolderTypeSendOnly:
  12. return "sendonly"
  13. case FolderTypeReceiveOnly:
  14. return "receiveonly"
  15. case FolderTypeReceiveEncrypted:
  16. return "receiveencrypted"
  17. default:
  18. return "unknown"
  19. }
  20. }
  21. func (t FolderType) MarshalText() ([]byte, error) {
  22. return []byte(t.String()), nil
  23. }
  24. func (t *FolderType) UnmarshalText(bs []byte) error {
  25. switch string(bs) {
  26. case "readwrite", "sendreceive":
  27. *t = FolderTypeSendReceive
  28. case "readonly", "sendonly":
  29. *t = FolderTypeSendOnly
  30. case "receiveonly":
  31. *t = FolderTypeReceiveOnly
  32. case "receiveencrypted":
  33. *t = FolderTypeReceiveEncrypted
  34. default:
  35. *t = FolderTypeSendReceive
  36. }
  37. return nil
  38. }