tuning.go 913 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 int
  8. const (
  9. // N.b. these constants must match those in lib/db.Tuning!
  10. TuningAuto Tuning = iota // default is auto
  11. TuningSmall
  12. TuningLarge
  13. )
  14. func (t Tuning) String() string {
  15. switch t {
  16. case TuningAuto:
  17. return "auto"
  18. case TuningSmall:
  19. return "small"
  20. case TuningLarge:
  21. return "large"
  22. default:
  23. return "unknown"
  24. }
  25. }
  26. func (t Tuning) MarshalText() ([]byte, error) {
  27. return []byte(t.String()), nil
  28. }
  29. func (t *Tuning) UnmarshalText(bs []byte) error {
  30. switch string(bs) {
  31. case "auto":
  32. *t = TuningAuto
  33. case "small":
  34. *t = TuningSmall
  35. case "large":
  36. *t = TuningLarge
  37. default:
  38. *t = TuningAuto
  39. }
  40. return nil
  41. }