authmode.go 706 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (C) 2018 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 AuthMode) String() string {
  8. switch t {
  9. case AuthModeStatic:
  10. return "static"
  11. case AuthModeLDAP:
  12. return "ldap"
  13. default:
  14. return "unknown"
  15. }
  16. }
  17. func (t AuthMode) MarshalText() ([]byte, error) {
  18. return []byte(t.String()), nil
  19. }
  20. func (t *AuthMode) UnmarshalText(bs []byte) error {
  21. switch string(bs) {
  22. case "ldap":
  23. *t = AuthModeLDAP
  24. case "static":
  25. *t = AuthModeStatic
  26. default:
  27. *t = AuthModeStatic
  28. }
  29. return nil
  30. }