From 5015614fdcc57786635412136bdf719e6808d251 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 14 Sep 2015 23:17:33 +0800 Subject: [PATCH] golint pagination --- utils/pagination/controller.go | 2 +- utils/pagination/doc.go | 3 +-- utils/pagination/paginator.go | 34 +++++++++++++++++----------------- utils/pagination/utils.go | 4 ++-- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/utils/pagination/controller.go b/utils/pagination/controller.go index f63b30e9..e42c4075 100644 --- a/utils/pagination/controller.go +++ b/utils/pagination/controller.go @@ -18,7 +18,7 @@ import ( "github.com/astaxie/beego/context" ) -// Instantiates a Paginator and assigns it to context.Input.Data["paginator"]. +// SetPaginator Instantiates a Paginator and assigns it to context.Input.Data["paginator"]. func SetPaginator(context *context.Context, per int, nums int64) (paginator *Paginator) { paginator = NewPaginator(context.Request, per, nums) context.Input.Data["paginator"] = &paginator diff --git a/utils/pagination/doc.go b/utils/pagination/doc.go index df0fa3b7..9abc6d78 100644 --- a/utils/pagination/doc.go +++ b/utils/pagination/doc.go @@ -1,6 +1,5 @@ /* - -The pagination package provides utilities to setup a paginator within the +Package pagination provides utilities to setup a paginator within the context of a http request. Usage diff --git a/utils/pagination/paginator.go b/utils/pagination/paginator.go index e813f798..c6db31e0 100644 --- a/utils/pagination/paginator.go +++ b/utils/pagination/paginator.go @@ -33,7 +33,7 @@ type Paginator struct { page int } -// Returns the total number of pages. +// PageNums Returns the total number of pages. func (p *Paginator) PageNums() int { if p.pageNums != 0 { return p.pageNums @@ -46,17 +46,17 @@ func (p *Paginator) PageNums() int { return p.pageNums } -// Returns the total number of items (e.g. from doing SQL count). +// Nums Returns the total number of items (e.g. from doing SQL count). func (p *Paginator) Nums() int64 { return p.nums } -// Sets the total number of items. +// SetNums Sets the total number of items. func (p *Paginator) SetNums(nums interface{}) { - p.nums, _ = ToInt64(nums) + p.nums, _ = toInt64(nums) } -// Returns the current page. +// Page Returns the current page. func (p *Paginator) Page() int { if p.page != 0 { return p.page @@ -74,7 +74,7 @@ func (p *Paginator) Page() int { return p.page } -// Returns a list of all pages. +// Pages Returns a list of all pages. // // Usage (in a view template): // @@ -112,7 +112,7 @@ func (p *Paginator) Pages() []int { return p.pageRange } -// Returns URL for a given page index. +// PageLink Returns URL for a given page index. func (p *Paginator) PageLink(page int) string { link, _ := url.ParseRequestURI(p.Request.URL.String()) values := link.Query() @@ -125,7 +125,7 @@ func (p *Paginator) PageLink(page int) string { return link.String() } -// Returns URL to the previous page. +// PageLinkPrev Returns URL to the previous page. func (p *Paginator) PageLinkPrev() (link string) { if p.HasPrev() { link = p.PageLink(p.Page() - 1) @@ -133,7 +133,7 @@ func (p *Paginator) PageLinkPrev() (link string) { return } -// Returns URL to the next page. +// PageLinkNext Returns URL to the next page. func (p *Paginator) PageLinkNext() (link string) { if p.HasNext() { link = p.PageLink(p.Page() + 1) @@ -141,42 +141,42 @@ func (p *Paginator) PageLinkNext() (link string) { return } -// Returns URL to the first page. +// PageLinkFirst Returns URL to the first page. func (p *Paginator) PageLinkFirst() (link string) { return p.PageLink(1) } -// Returns URL to the last page. +// PageLinkLast Returns URL to the last page. func (p *Paginator) PageLinkLast() (link string) { return p.PageLink(p.PageNums()) } -// Returns true if the current page has a predecessor. +// HasPrev Returns true if the current page has a predecessor. func (p *Paginator) HasPrev() bool { return p.Page() > 1 } -// Returns true if the current page has a successor. +// HasNext Returns true if the current page has a successor. func (p *Paginator) HasNext() bool { return p.Page() < p.PageNums() } -// Returns true if the given page index points to the current page. +// IsActive Returns true if the given page index points to the current page. func (p *Paginator) IsActive(page int) bool { return p.Page() == page } -// Returns the current offset. +// Offset Returns the current offset. func (p *Paginator) Offset() int { return (p.Page() - 1) * p.PerPageNums } -// Returns true if there is more than one page. +// HasPages Returns true if there is more than one page. func (p *Paginator) HasPages() bool { return p.PageNums() > 1 } -// Instantiates a paginator struct for the current http request. +// NewPaginator Instantiates a paginator struct for the current http request. func NewPaginator(req *http.Request, per int, nums interface{}) *Paginator { p := Paginator{} p.Request = req diff --git a/utils/pagination/utils.go b/utils/pagination/utils.go index 5932647d..686e68b0 100644 --- a/utils/pagination/utils.go +++ b/utils/pagination/utils.go @@ -19,8 +19,8 @@ import ( "reflect" ) -// convert any numeric value to int64 -func ToInt64(value interface{}) (d int64, err error) { +// ToInt64 convert any numeric value to int64 +func toInt64(value interface{}) (d int64, err error) { val := reflect.ValueOf(value) switch value.(type) { case int, int8, int16, int32, int64: