user.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2015 - Present, The Gogs Authors. All rights reserved.
  2. // Copyright 2018 - Present, Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package errors
  7. import "fmt"
  8. // EmptyName represents a "RepoNotExist" kind of error
  9. type EmptyName struct{}
  10. // IsEmptyName checks if an error is a EmptyName
  11. func IsEmptyName(err error) bool {
  12. _, ok := err.(EmptyName)
  13. return ok
  14. }
  15. func (err EmptyName) Error() string {
  16. return "empty name"
  17. }
  18. // UserNotExist represents a "UserNotExist" kind of error
  19. type UserNotExist struct {
  20. UserID int64
  21. Name string
  22. }
  23. // IsUserNotExist checks if an error is a UserNotExist
  24. func IsUserNotExist(err error) bool {
  25. _, ok := err.(UserNotExist)
  26. return ok
  27. }
  28. func (err UserNotExist) Error() string {
  29. return fmt.Sprintf("user does not exist [user_id: %d, name: %s]", err.UserID, err.Name)
  30. }
  31. // UserNotKeyOwner represents a "UserNotKeyOwner" kind of error
  32. type UserNotKeyOwner struct {
  33. KeyID int64
  34. }
  35. // IsUserNotKeyOwner checks if an error is a UserNotKeyOwner
  36. func IsUserNotKeyOwner(err error) bool {
  37. _, ok := err.(UserNotKeyOwner)
  38. return ok
  39. }
  40. func (err UserNotKeyOwner) Error() string {
  41. return fmt.Sprintf("user is not the owner of public key [key_id: %d]", err.KeyID)
  42. }