1
0

authmode.go 796 B

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