types.go 745 B

1234567891011121314151617181920212223242526272829303132333435
  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 fs
  7. func (t FilesystemType) String() string {
  8. switch t {
  9. case FilesystemTypeBasic:
  10. return "basic"
  11. case FilesystemTypeFake:
  12. return "fake"
  13. default:
  14. return "unknown"
  15. }
  16. }
  17. func (t FilesystemType) MarshalText() ([]byte, error) {
  18. return []byte(t.String()), nil
  19. }
  20. func (t *FilesystemType) UnmarshalText(bs []byte) error {
  21. switch string(bs) {
  22. case "basic":
  23. *t = FilesystemTypeBasic
  24. case "fake":
  25. *t = FilesystemTypeFake
  26. default:
  27. *t = FilesystemTypeBasic
  28. }
  29. return nil
  30. }