util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// PAGENUM identity the page number of the data.
	// The default value is 0.
	PAGENUM = "pageNum"

	// PAGESIZE identity the page size of the data.
	// If this value equals 0, return all values.
	PAGESIZE = "pageSize"

	// SORTKEY identity the sort key of the data.
	// Each mgr needs to define acceptable values based on its own implementation.
	SORTKEY = "sortKey"

	// SORTDIRECT identity the sort direct of the data.
	// The value can only be ASC or DESC.
	SORTDIRECT = "sortDirect"

	// ASCDIRECT means to sort the records in ascending order.
	ASCDIRECT = "ASC"

	// DESCDIRECT means to sort the records in descending order.
	DESCDIRECT = "DESC"
)

Variables

This section is empty.

Functions

func GetPageValues

func GetPageValues(metaSlice []interface{}, pageNum, pageSize int,
	less func(i, j int) bool) []interface{}

GetPageValues gets some pages of metaSlice after ordering it. The less is a function that reports whether the element with index i should sort before the element with index j.

Eg:

people := []struct {
    Name string
    Age  int
}{
    {"Gopher", 7},
    {"Alice", 55},
    {"Vera", 24},
    {"Bob", 75},
}

If you want to sort it by age, and the less function should be defined as follows:

less := func(i, j int) bool { return people[i].Age < people[j].Age }

func IsDESC

func IsDESC(str string) bool

IsDESC returns whether the sortDirect is desc.

func ValidateFilter

func ValidateFilter(pageFilter *PageFilter, sortKeyMap map[string]bool) error

ValidateFilter validates the param of filter. The caller should customize the sortKeyMap which specifies the sort keys it supports.

Types

type PageFilter

type PageFilter struct {
	PageNum    int
	PageSize   int
	SortKey    []string
	SortDirect string
}

PageFilter is a struct.

func ParseFilter

func ParseFilter(req *http.Request, sortKeyMap map[string]bool) (pageFilter *PageFilter, err error)

ParseFilter gets filter params from request and returns a map[string][]string.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store maintains some metadata information in memory.

func NewStore

func NewStore() *Store

NewStore returns a new Store.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete a key-value pair from the store with specified key.

func (*Store) Get

func (s *Store) Get(key string) (interface{}, error)

Get a key-value pair from the store.

func (*Store) List

func (s *Store) List() []interface{}

List returns all key-value pairs in the store. And the order of results is random.

func (*Store) Put

func (s *Store) Put(key string, value interface{}) error

Put a key-value pair into the store.

Jump to

Keyboard shortcuts

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