ripple-api/common/paginate.go
2016-11-21 16:27:21 +01:00

23 lines
360 B
Go

package common
import "fmt"
// Paginate creates an additional SQL LIMIT clause for paginating.
func Paginate(page, limit string, maxLimit int) string {
var (
p = Int(page)
l = Int(limit)
)
if p < 1 {
p = 1
}
if l < 1 {
l = 50
}
if l > maxLimit {
l = maxLimit
}
start := uint(p-1) * uint(l)
return fmt.Sprintf(" LIMIT %d,%d ", start, l)
}