fix: fixing up some logic

This commit is contained in:
Reinaldy Rafli 2021-11-08 22:55:07 +07:00
parent 955313b45e
commit 843f1d77c3
No known key found for this signature in database
GPG Key ID: CFDB9400255D8CB6
10 changed files with 23 additions and 19 deletions

View File

@ -128,7 +128,7 @@ func GetCachedJokeByID(memory *bigcache.BigCache, id int) (string, error) {
var data []schema.Joke
err = ffjson.Unmarshal(jokes, &data)
if err != nil {
return "", nil
return "", err
}
// This is a simple solution, might convert it to goroutines and channels sometime soon.
@ -150,8 +150,12 @@ func GetCachedTotalJokes(memory *bigcache.BigCache) (int, error) {
}
return 0, err
}
i, err := strconv.Atoi(string(total))
if err != nil {
return 0, err
}
return int(total[0]), nil
return i, nil
}
func CheckJokeExists(db *pgxpool.Pool, ctx context.Context, id string) (bool, error) {
@ -174,7 +178,7 @@ func CheckJokeExists(db *pgxpool.Pool, ctx context.Context, id string) (bool, er
var jokeID int
err = conn.QueryRow(ctx, sql, args...).Scan(&jokeID)
if err != nil && err != pgx.ErrNoRows {
if err != nil && errors.Is(err, pgx.ErrNoRows) {
return false, err
}