Skip to content

Commit

Permalink
Bug from to fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Dodi committed Jun 29, 2020
1 parent 4795f94 commit 418bd9a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion paginator/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/jinzhu/gorm"
"math"
"net/http"
"reflect"
)

type Param struct {
Expand Down Expand Up @@ -65,7 +66,12 @@ func Paginate(p *Param, result interface{}) *Pagination {
} else {
offset = (p.Page - 1) * p.Limit
}
db.Limit(p.Limit).Offset(offset).Find(result).Count(&countInPage)
db.Limit(p.Limit).Offset(offset).Find(result)

indirect := reflect.ValueOf(result)
if indirect.IsValid() && indirect.Elem().Kind() == reflect.Slice {
countInPage = indirect.Elem().Len()
}
<-done

paginate.FirstPageUrl = fmt.Sprintf("%s%s?page=%d", p.Req.Host, p.Req.URL.Path, 1)
Expand Down

0 comments on commit 418bd9a

Please sign in to comment.