tuning.go 856 B

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