Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataProvider ¶
type DataProvider interface { Models() interface{} Count() int TotalCount() int Pagination() *Pagination }
DataProvider interface provides a mechanism to paginate data
type OkResponse ¶
type OkResponse struct { Code int `json:"code"` Result []interface{} `json:"result"` }
OkResponse is the response for a successful request.
type PageAbleObj ¶
type PageAbleObj struct { Models interface{} `json:"list"` Page int `json:"page"` PageSize int `json:"page_size"` CurrentCount int `json:"current_count"` TotalCount int `json:"total_count"` TotalPage int `json:"total_page"` }
PageAbleObj is used to create response data.
type Pagination ¶
Pagination represents information relevant to pagination of data items.
func NewHttpPager ¶
func NewHttpPager(req *http.Request) *Pagination
NewHttpPager creates and returns the Pagination by the http GET params.
func (*Pagination) Offset ¶
func (p *Pagination) Offset() int
Offset returns the offset of current page.
func (*Pagination) PageCount ¶
func (p *Pagination) PageCount() int
PageCount returns the page count.
type RestServer ¶
type RestServer struct { Addr string Srv *gmqtt.Server User gin.Accounts //BasicAuth user info,username => password }
RestServer represents the REST API server.
type SliceDataProvider ¶
type SliceDataProvider struct { Pager *Pagination // contains filtered or unexported fields }
SliceDataProvider implements DataProvider
func (*SliceDataProvider) Count ¶
func (cp *SliceDataProvider) Count() int
Count returns the item count of current page.
func (*SliceDataProvider) Models ¶
func (cp *SliceDataProvider) Models(out interface{}) error
Models set the models of current page into out param.
func (*SliceDataProvider) Pagination ¶
func (cp *SliceDataProvider) Pagination() *Pagination
Pagination returns the Pagination struct.
func (*SliceDataProvider) SetModels ¶
func (cp *SliceDataProvider) SetModels(models interface{})
SetModels sets the models into DataProvide.
func (*SliceDataProvider) TotalCount ¶
func (cp *SliceDataProvider) TotalCount() int
TotalCount returns the total count of all models