login_source.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2017 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package errors
  5. import "fmt"
  6. type LoginSourceNotExist struct {
  7. ID int64
  8. }
  9. func IsLoginSourceNotExist(err error) bool {
  10. _, ok := err.(LoginSourceNotExist)
  11. return ok
  12. }
  13. func (err LoginSourceNotExist) Error() string {
  14. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  15. }
  16. type LoginSourceNotActivated struct {
  17. SourceID int64
  18. }
  19. func IsLoginSourceNotActivated(err error) bool {
  20. _, ok := err.(LoginSourceNotActivated)
  21. return ok
  22. }
  23. func (err LoginSourceNotActivated) Error() string {
  24. return fmt.Sprintf("login source is not activated [source_id: %d]", err.SourceID)
  25. }
  26. type InvalidLoginSourceType struct {
  27. Type interface{}
  28. }
  29. func IsInvalidLoginSourceType(err error) bool {
  30. _, ok := err.(InvalidLoginSourceType)
  31. return ok
  32. }
  33. func (err InvalidLoginSourceType) Error() string {
  34. return fmt.Sprintf("invalid login source type [type: %v]", err.Type)
  35. }
  36. type LoginSourceMismatch struct {
  37. Expect int64
  38. Actual int64
  39. }
  40. func IsLoginSourceMismatch(err error) bool {
  41. _, ok := err.(LoginSourceMismatch)
  42. return ok
  43. }
  44. func (err LoginSourceMismatch) Error() string {
  45. return fmt.Sprintf("login source mismatch [expect: %d, actual: %d]", err.Expect, err.Actual)
  46. }