Add basic friend logic

This commit is contained in:
Howl
2016-04-07 11:20:35 +02:00
parent f7819630ee
commit af71442e79
4 changed files with 153 additions and 0 deletions

33
common/paginate.go Normal file
View File

@@ -0,0 +1,33 @@
package common
import (
"fmt"
"strconv"
)
// Paginate creates an additional SQL LIMIT clause for paginating.
func Paginate(page, limit string) string {
var (
pInt int
lInt int
err error
)
if page == "" {
pInt = 1
} else {
pInt, err = strconv.Atoi(page)
if err != nil {
pInt = 1
}
}
if limit == "" {
lInt = 50
} else {
lInt, err = strconv.Atoi(limit)
if err != nil {
lInt = 50
}
}
start := (pInt - 1) * lInt
return fmt.Sprintf(" LIMIT %d,%d ", start, lInt)
}