Skip to content

Commit

Permalink
Add paginable interface to loosen buffalo ties to pop (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislas-m authored Mar 6, 2019
1 parent 07118a2 commit c276e05
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ var PaginatorPageKey = "page"
// to override the default one
var PaginatorPerPageKey = "per_page"

type paginable interface {
Paginate() string
}

var _ paginable = Paginator{}

// Paginator is a type used to represent the pagination of records
// from the database.
type Paginator struct {
Expand All @@ -34,11 +40,16 @@ type Paginator struct {
TotalPages int `json:"total_pages"`
}

func (p Paginator) String() string {
// Paginate implements the paginable interface.
func (p Paginator) Paginate() string {
b, _ := json.Marshal(p)
return string(b)
}

func (p Paginator) String() string {
return p.Paginate()
}

// NewPaginator returns a new `Paginator` value with the appropriate
// defaults set.
func NewPaginator(page int, perPage int) *Paginator {
Expand Down

0 comments on commit c276e05

Please sign in to comment.