foldertype.go 1.0 KB

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