hanayo/vendor/zxq.co/ripple/rippleapi/common/paginate.go
2019-02-23 13:29:15 +00: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)
}