use error.Is instead of equality check

This commit is contained in:
Lars Hoogestraat 2020-12-07 16:29:14 +01:00
parent f1dc6fa95a
commit f416c8a55d
3 changed files with 7 additions and 13 deletions

View File

@ -17,13 +17,7 @@ type SQLiteConfig struct {
//Open receives handle for sqlite database, returns an error if connection failed
func (d SQLiteConfig) Open() (*sql.DB, error) {
db, err := sql.Open("sqlite3", d.File)
if err != nil {
return nil, err
}
return db, nil
return sql.Open("sqlite3", d.File)
}
//InitTables creates the tables

View File

@ -76,7 +76,7 @@ func (a *Article) slug(as ArticleService, now time.Time) error {
_, err := as.Datasource.GetBySlug(a.Slug, nil, All)
if err != nil {
if err == sql.ErrNoRows {
if errors.Is(err, sql.ErrNoRows) {
break
}
return err
@ -210,7 +210,7 @@ func (as ArticleService) GetBySlug(s string, u *User, pc PublishedCriteria) (*Ar
a, err := as.Datasource.GetBySlug(s, u, pc)
if err != nil {
if err == sql.ErrNoRows {
if errors.Is(err, sql.ErrNoRows) {
return nil, httperror.NotFound("article", err)
}
return nil, err
@ -233,7 +233,7 @@ func (as ArticleService) GetByID(id int, u *User, pc PublishedCriteria) (*Articl
a, err := as.Datasource.Get(id, u, pc)
if err != nil {
if err == sql.ErrNoRows {
if errors.Is(err, sql.ErrNoRows) {
return nil, httperror.NotFound("article", fmt.Errorf("the article with id %d was not found", id))
}
return nil, err

View File

@ -66,7 +66,7 @@ func (cs CategoryService) GetBySlug(s string, fc FilterCriteria) (*Category, err
c, err := cs.Datasource.GetBySlug(s, fc)
if err != nil {
if err == sql.ErrNoRows {
if errors.Is(err, sql.ErrNoRows) {
return nil, httperror.NotFound("category", fmt.Errorf("the category with slug %s was not found", s))
}
return nil, err
@ -79,7 +79,7 @@ func (cs CategoryService) GetByID(id int, fc FilterCriteria) (*Category, error)
c, err := cs.Datasource.Get(id, fc)
if err != nil {
if err == sql.ErrNoRows {
if errors.Is(err, sql.ErrNoRows) {
return nil, httperror.NotFound("category", fmt.Errorf("the category with id %d was not found", id))
}
return nil, err
@ -103,7 +103,7 @@ func (cs CategoryService) Create(c *Category) (int, error) {
_, err := cs.Datasource.GetBySlug(c.Slug, AllCategories)
if err != nil {
if err == sql.ErrNoRows {
if errors.Is(err, sql.ErrNoRows) {
break
}
return -1, err