tuning.go 754 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2019 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. func (t Tuning) String() string {
  8. switch t {
  9. case TuningAuto:
  10. return "auto"
  11. case TuningSmall:
  12. return "small"
  13. case TuningLarge:
  14. return "large"
  15. default:
  16. return "unknown"
  17. }
  18. }
  19. func (t Tuning) MarshalText() ([]byte, error) {
  20. return []byte(t.String()), nil
  21. }
  22. func (t *Tuning) UnmarshalText(bs []byte) error {
  23. switch string(bs) {
  24. case "auto":
  25. *t = TuningAuto
  26. case "small":
  27. *t = TuningSmall
  28. case "large":
  29. *t = TuningLarge
  30. default:
  31. *t = TuningAuto
  32. }
  33. return nil
  34. }