Skip to content

Commit

Permalink
refactor: move offset function to internal (#11)
Browse files Browse the repository at this point in the history
* refactor: move offset function to internal

* refactor: rename function offset to getOffset
  • Loading branch information
mhseptiadi authored Sep 27, 2019
1 parent 7a544f2 commit 276042f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/go-redsync/redsync"
redigo "github.com/gomodule/redigo/redis"
"github.com/jpillora/backoff"
"github.com/kumparan/go-lib/utils"
)

const (
Expand Down Expand Up @@ -485,7 +484,7 @@ func (k *keeper) GetAndRemoveLastListElement(name string) (value interface{}, er
}

func (k *keeper) GetList(name string, size int64, page int64) (value interface{}, err error) {
offset := utils.Offset(page, size)
offset := getOffset(page, size)

client := k.connPool.Get()
defer client.Close()
Expand Down Expand Up @@ -517,3 +516,12 @@ func (k *keeper) GetTTL(name string) (value int64, err error) {
value = val.(int64)
return
}

// getOffset to get offset from page and limit, min value for page = 1
func getOffset(page, limit int64) int64 {
offset := (page - 1) * limit
if offset < 0 {
return 0
}
return offset
}

0 comments on commit 276042f

Please sign in to comment.