Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
5015614f
Commit
5015614f
authored
Sep 14, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
golint pagination
parent
7b81617a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
22 deletions
+21
-22
controller.go
utils/pagination/controller.go
+1
-1
doc.go
utils/pagination/doc.go
+1
-2
paginator.go
utils/pagination/paginator.go
+17
-17
utils.go
utils/pagination/utils.go
+2
-2
No files found.
utils/pagination/controller.go
View file @
5015614f
...
@@ -18,7 +18,7 @@ import (
...
@@ -18,7 +18,7 @@ import (
"github.com/astaxie/beego/context"
"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
)
{
func
SetPaginator
(
context
*
context
.
Context
,
per
int
,
nums
int64
)
(
paginator
*
Paginator
)
{
paginator
=
NewPaginator
(
context
.
Request
,
per
,
nums
)
paginator
=
NewPaginator
(
context
.
Request
,
per
,
nums
)
context
.
Input
.
Data
[
"paginator"
]
=
&
paginator
context
.
Input
.
Data
[
"paginator"
]
=
&
paginator
...
...
utils/pagination/doc.go
View file @
5015614f
/*
/*
Package pagination provides utilities to setup a paginator within the
The pagination package provides utilities to setup a paginator within the
context of a http request.
context of a http request.
Usage
Usage
...
...
utils/pagination/paginator.go
View file @
5015614f
...
@@ -33,7 +33,7 @@ type Paginator struct {
...
@@ -33,7 +33,7 @@ type Paginator struct {
page
int
page
int
}
}
// Returns the total number of pages.
//
PageNums
Returns the total number of pages.
func
(
p
*
Paginator
)
PageNums
()
int
{
func
(
p
*
Paginator
)
PageNums
()
int
{
if
p
.
pageNums
!=
0
{
if
p
.
pageNums
!=
0
{
return
p
.
pageNums
return
p
.
pageNums
...
@@ -46,17 +46,17 @@ func (p *Paginator) PageNums() int {
...
@@ -46,17 +46,17 @@ func (p *Paginator) PageNums() int {
return
p
.
pageNums
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
{
func
(
p
*
Paginator
)
Nums
()
int64
{
return
p
.
nums
return
p
.
nums
}
}
// Sets the total number of items.
// Set
Nums Set
s the total number of items.
func
(
p
*
Paginator
)
SetNums
(
nums
interface
{})
{
func
(
p
*
Paginator
)
SetNums
(
nums
interface
{})
{
p
.
nums
,
_
=
T
oInt64
(
nums
)
p
.
nums
,
_
=
t
oInt64
(
nums
)
}
}
// Returns the current page.
//
Page
Returns the current page.
func
(
p
*
Paginator
)
Page
()
int
{
func
(
p
*
Paginator
)
Page
()
int
{
if
p
.
page
!=
0
{
if
p
.
page
!=
0
{
return
p
.
page
return
p
.
page
...
@@ -74,7 +74,7 @@ func (p *Paginator) Page() int {
...
@@ -74,7 +74,7 @@ func (p *Paginator) Page() int {
return
p
.
page
return
p
.
page
}
}
// Returns a list of all pages.
//
Pages
Returns a list of all pages.
//
//
// Usage (in a view template):
// Usage (in a view template):
//
//
...
@@ -112,7 +112,7 @@ func (p *Paginator) Pages() []int {
...
@@ -112,7 +112,7 @@ func (p *Paginator) Pages() []int {
return
p
.
pageRange
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
{
func
(
p
*
Paginator
)
PageLink
(
page
int
)
string
{
link
,
_
:=
url
.
ParseRequestURI
(
p
.
Request
.
URL
.
String
())
link
,
_
:=
url
.
ParseRequestURI
(
p
.
Request
.
URL
.
String
())
values
:=
link
.
Query
()
values
:=
link
.
Query
()
...
@@ -125,7 +125,7 @@ func (p *Paginator) PageLink(page int) string {
...
@@ -125,7 +125,7 @@ func (p *Paginator) PageLink(page int) string {
return
link
.
String
()
return
link
.
String
()
}
}
// Returns URL to the previous page.
//
PageLinkPrev
Returns URL to the previous page.
func
(
p
*
Paginator
)
PageLinkPrev
()
(
link
string
)
{
func
(
p
*
Paginator
)
PageLinkPrev
()
(
link
string
)
{
if
p
.
HasPrev
()
{
if
p
.
HasPrev
()
{
link
=
p
.
PageLink
(
p
.
Page
()
-
1
)
link
=
p
.
PageLink
(
p
.
Page
()
-
1
)
...
@@ -133,7 +133,7 @@ func (p *Paginator) PageLinkPrev() (link string) {
...
@@ -133,7 +133,7 @@ func (p *Paginator) PageLinkPrev() (link string) {
return
return
}
}
// Returns URL to the next page.
//
PageLinkNext
Returns URL to the next page.
func
(
p
*
Paginator
)
PageLinkNext
()
(
link
string
)
{
func
(
p
*
Paginator
)
PageLinkNext
()
(
link
string
)
{
if
p
.
HasNext
()
{
if
p
.
HasNext
()
{
link
=
p
.
PageLink
(
p
.
Page
()
+
1
)
link
=
p
.
PageLink
(
p
.
Page
()
+
1
)
...
@@ -141,42 +141,42 @@ func (p *Paginator) PageLinkNext() (link string) {
...
@@ -141,42 +141,42 @@ func (p *Paginator) PageLinkNext() (link string) {
return
return
}
}
// Returns URL to the first page.
//
PageLinkFirst
Returns URL to the first page.
func
(
p
*
Paginator
)
PageLinkFirst
()
(
link
string
)
{
func
(
p
*
Paginator
)
PageLinkFirst
()
(
link
string
)
{
return
p
.
PageLink
(
1
)
return
p
.
PageLink
(
1
)
}
}
// Returns URL to the last page.
//
PageLinkLast
Returns URL to the last page.
func
(
p
*
Paginator
)
PageLinkLast
()
(
link
string
)
{
func
(
p
*
Paginator
)
PageLinkLast
()
(
link
string
)
{
return
p
.
PageLink
(
p
.
PageNums
())
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
{
func
(
p
*
Paginator
)
HasPrev
()
bool
{
return
p
.
Page
()
>
1
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
{
func
(
p
*
Paginator
)
HasNext
()
bool
{
return
p
.
Page
()
<
p
.
PageNums
()
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
{
func
(
p
*
Paginator
)
IsActive
(
page
int
)
bool
{
return
p
.
Page
()
==
page
return
p
.
Page
()
==
page
}
}
// Returns the current offset.
//
Offset
Returns the current offset.
func
(
p
*
Paginator
)
Offset
()
int
{
func
(
p
*
Paginator
)
Offset
()
int
{
return
(
p
.
Page
()
-
1
)
*
p
.
PerPageNums
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
{
func
(
p
*
Paginator
)
HasPages
()
bool
{
return
p
.
PageNums
()
>
1
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
{
func
NewPaginator
(
req
*
http
.
Request
,
per
int
,
nums
interface
{})
*
Paginator
{
p
:=
Paginator
{}
p
:=
Paginator
{}
p
.
Request
=
req
p
.
Request
=
req
...
...
utils/pagination/utils.go
View file @
5015614f
...
@@ -19,8 +19,8 @@ import (
...
@@ -19,8 +19,8 @@ import (
"reflect"
"reflect"
)
)
// convert any numeric value to int64
//
ToInt64
convert any numeric value to int64
func
T
oInt64
(
value
interface
{})
(
d
int64
,
err
error
)
{
func
t
oInt64
(
value
interface
{})
(
d
int64
,
err
error
)
{
val
:=
reflect
.
ValueOf
(
value
)
val
:=
reflect
.
ValueOf
(
value
)
switch
value
.
(
type
)
{
switch
value
.
(
type
)
{
case
int
,
int8
,
int16
,
int32
,
int64
:
case
int
,
int8
,
int16
,
int32
,
int64
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment