ldaptransport.go 970 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 LDAPTransport int
  8. const (
  9. LDAPTransportPlain LDAPTransport = iota // default is plain
  10. LDAPTransportTLS
  11. LDAPTransportStartTLS
  12. )
  13. func (t LDAPTransport) String() string {
  14. switch t {
  15. case LDAPTransportPlain:
  16. return "plain"
  17. case LDAPTransportTLS:
  18. return "tls"
  19. case LDAPTransportStartTLS:
  20. return "starttls"
  21. default:
  22. return "unknown"
  23. }
  24. }
  25. func (t LDAPTransport) MarshalText() ([]byte, error) {
  26. return []byte(t.String()), nil
  27. }
  28. func (t *LDAPTransport) UnmarshalText(bs []byte) error {
  29. switch string(bs) {
  30. case "plain":
  31. *t = LDAPTransportPlain
  32. case "tls":
  33. *t = LDAPTransportTLS
  34. case "starttls":
  35. *t = LDAPTransportStartTLS
  36. default:
  37. *t = LDAPTransportPlain
  38. }
  39. return nil
  40. }