domain

package
v0.0.0-...-82e7740 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 10 Imported by: 5

README

data-domain GoDoc

domain library for Go

Installation

go get gopkg.in/goyy/goyy.v0/data/domain

Documentation

Overview

Package domain implements domain utility functions.

Usage

p := domain.NewPageable(1, 10)
fmt.Println(p.PageNo())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetPriority

func SetPriority(value int)

SetPriority set the priority of the logger.

func SiftsToMap

func SiftsToMap(sifts ...Sift) map[string]interface{}

SiftsToMap returns the map from []Sift.

func SiftsToParams

func SiftsToParams(sifts ...Sift) map[string]string

SiftsToParams returns the params(map) from []Sift.

Types

type Page

type Page interface {
	Pageable
	Pagination

	// Returns the previous Pageable or the first Pageable
	// if the current one already is the first one.
	// @return
	Previous() Pageable

	// Returns the Pageable requesting the next Page.
	// @return
	Next() Pageable

	// Returns the Pageable requesting the first page.
	// @return
	First() Pageable

	// Returns the Pageable requesting the last page.
	// @return
	Last() Pageable

	// Returns whether there's a previous Pageable we can access from
	// the current one. Will return false in case the current
	// Pageable already refers to the first page.
	// @return
	HasPrevious() bool

	// Returns whether there's a next Pageable we can access from
	// the current one. Will return false in case the current
	// Pageable already refers to the last page.
	// @return
	HasNext() bool

	// Returns whether the current Pageable is the first one.
	//@return
	IsFirst() bool

	// Returns whether the current Pageable is the last one.
	// @return
	IsLast() bool

	// Returns the number of total pages.
	// @return the number of total pages
	TotalPages() int

	// Returns the total amount of elements.
	// @return the total amount of elements
	TotalElements() int

	// Returns the page content as entity.Interfaces.
	// @return
	Content() entity.Interfaces

	// Returns the page content as slice.
	// @return
	Slice() interface{}

	// Set total amount of elements.
	SetTotalElements(totalElements int)

	// Set pageable information.
	SetPageable(pageable Pageable)

	// Set pagination information.
	SetPagination(pagination Pagination)
}

Page a page is a sublist of a list of objects. It allows gain information about the position of it in the containing entire list.

func NewPage

func NewPage(pageable Pageable, content entity.Interfaces, totalElements int) Page

NewPage returns the Page from pageable, content, totalElements.

func NewPageDefault

func NewPageDefault(content entity.Interfaces) Page

NewPageDefault returns the default Page.

type Pageable

type Pageable interface {

	// Returns the page to be returned.
	// @return the page to be returned.
	PageNo() int

	// Returns the number of items to be returned.
	// @return the number of items of that page
	PageSize() int

	// Returns the offset to be taken according to the underlying page and page size.
	// @return the offset to be taken
	Offset() int
}

Pageable abstract interface for pagination information.

func NewPageable

func NewPageable(pageNo, pageSize int) Pageable

NewPageable returns the Pageable from pageNo, pageSize.

func NewPageableHTTP

func NewPageableHTTP(w http.ResponseWriter, r *http.Request) (Pageable, error)

NewPageableHTTP returns the Pageable from HTTP.

func NewPageablePageNo

func NewPageablePageNo(pageNo int) Pageable

NewPageablePageNo returns the Pageable from pageNo. PageSize defaults to 10

type Pagination

type Pagination interface {
	Length() int
	Slider() int
	PageFn() string
}

Pagination abstract interface for pagination information.

func NewPagination

func NewPagination(length, slider int, pageFn string) Pagination

NewPagination returns the Pagination from length, slider, function.

func NewPaginationDefault

func NewPaginationDefault() Pagination

NewPaginationDefault returns the default Pagination. length defaults to 8 slider defaults to 1 function defaults to page

func NewPaginationLength

func NewPaginationLength(length int) Pagination

NewPaginationLength returns the Pagination from length. slider defaults to 1 function defaults to page

type Sift

type Sift interface {
	// Returns the name.
	// eg: sNameEQST
	// @return
	Name() string

	// Returns the name of query conditional filtering.
	// eg: Name
	// @return
	Key() string

	// Returns the value of query conditional filtering.
	// eg: goyy
	// @return
	Value() string

	// Returns the operator of query conditional filtering.
	// eg: EQ
	// @return
	Operator() string

	// Returns the type of query conditional filtering.
	// eg: ST
	// @return
	Type() string
}

Sift query conditional filtering. eg: sNameEQST=goyy

func NewSift

func NewSift(name, value string, prefix ...string) (Sift, bool)

NewSift returns the Sift from name, value. Prefix[s] + Name + Operator[EQ|NE|...|OD] + Type[ST|BL|...|TS] example: sName sNameEQ sNameEQST sNameSTEQ sAgeGT sMemoLI

func NewSiftDeletion

func NewSiftDeletion() (Sift, bool)

NewSiftDeletion returns the Sift: deletion = 0.

func NewSifts

func NewSifts(values url.Values, prefix ...string) ([]Sift, error)

NewSifts returns the []Sift from url.Values and prefix.

func NewSiftsReq

func NewSiftsReq(req *http.Request, prefix ...string) ([]Sift, error)

NewSiftsReq returns the []Sift from http.Request and prefix.

Jump to

Keyboard shortcuts

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