util

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

Index

Constants

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

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

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

	// SORTDIRECT identifies 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 {
	*syncmap.SyncMap
}

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) 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