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