foldertype.go 1.4 KB

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