user.go 889 B

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