types.go 864 B

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