user.go 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 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. type EmptyName struct{}
  9. func IsEmptyName(err error) bool {
  10. _, ok := err.(EmptyName)
  11. return ok
  12. }
  13. func (err EmptyName) Error() string {
  14. return "empty name"
  15. }
  16. type UserNotExist struct {
  17. UserID int64
  18. Name string
  19. }
  20. func IsUserNotExist(err error) bool {
  21. _, ok := err.(UserNotExist)
  22. return ok
  23. }
  24. func (err UserNotExist) Error() string {
  25. return fmt.Sprintf("user does not exist [user_id: %d, name: %s]", err.UserID, err.Name)
  26. }
  27. type UserNotKeyOwner struct {
  28. KeyID int64
  29. }
  30. func IsUserNotKeyOwner(err error) bool {
  31. _, ok := err.(UserNotKeyOwner)
  32. return ok
  33. }
  34. func (err UserNotKeyOwner) Error() string {
  35. return fmt.Sprintf("user is not the owner of public key [key_id: %d]", err.KeyID)
  36. }