restapi

package
v0.0.0-...-dfa80c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2019 License: MIT Imports: 8 Imported by: 0

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

type Pagination struct {
	Page       int
	PageSize   int
	TotalCount int
}

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.

func (*RestServer) Run

func (rest *RestServer) Run()

Run starts the REST 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL