foldertype.go 890 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. default:
  16. return "unknown"
  17. }
  18. }
  19. func (t FolderType) MarshalText() ([]byte, error) {
  20. return []byte(t.String()), nil
  21. }
  22. func (t *FolderType) UnmarshalText(bs []byte) error {
  23. switch string(bs) {
  24. case "readwrite", "sendreceive":
  25. *t = FolderTypeSendReceive
  26. case "readonly", "sendonly":
  27. *t = FolderTypeSendOnly
  28. case "receiveonly":
  29. *t = FolderTypeReceiveOnly
  30. default:
  31. *t = FolderTypeSendReceive
  32. }
  33. return nil
  34. }