Blame view

pagination.go 676 Bytes
4635f2c3c   Marko Tikvić   pagination utility
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  package webutility
  
  import "net/http"
  
  type PaginationParams struct {
  	URL    string
  	Offset int64
  	Limit  int64
  	SortBy string
  	Order  string
  }
  
  func (p *PaginationParams) links() PaginationLinks {
  	return PaginationLinks{}
  }
  
  // PaginationLinks ...
  type PaginationLinks struct {
  	Count int64
  	Total int64
  	Base  string `json:"base"`
  	Next  string `json:"next"`
  	Prev  string `json:"prev"`
  	Self  string `json:"self"`
  }
  
  func GetPaginationParameters(req *http.Request) (p PaginationParams) {
  	p.Offset = StringToInt64(req.FormValue("offset"))
  	p.Limit = StringToInt64(req.FormValue("limit"))
  	p.SortBy = req.FormValue("sortBy")
  	p.Order = req.FormValue("order")
  
  	return p
  }