error.go 481 B

12345678910111213141516171819202122
  1. package dto
  2. import (
  3. "errors"
  4. "github.com/go-sql-driver/mysql"
  5. )
  6. var (
  7. GetFailedErr = errors.New("查询失败")
  8. CreateFailedErr = errors.New("添加失败")
  9. UpdateFailedErr = errors.New("更新失败")
  10. DeleteFailedErr = errors.New("删除失败")
  11. GetNotFoundErr = errors.New("数据不存在")
  12. )
  13. func IsUniqueIndexErr(err error) bool {
  14. uniqueErr := &mysql.MySQLError{}
  15. if ok := errors.As(err, &uniqueErr); ok {
  16. return uniqueErr.Number == 1062
  17. }
  18. return false
  19. }