sliceutil

package
v0.0.0-...-3241ae0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: GPL-3.0 Imports: 11 Imported by: 1

Documentation

Overview

* @Author: Wangjun * @Date: 2021-05-15 22:43:20 * @LastEditTime: 2022-05-20 14:58:51 * @LastEditors: Wangjun * @Description: * @FilePath: \golib\sliceutil\getter.go * hnxr

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asc

func Asc(slice interface{}, name string) (err error)

Asc Sort a slice in ascending order by a field name.

func Desc

func Desc(slice interface{}, name string) (err error)

Desc Sort a slice in descending order by a field name.

func OrderBy

func OrderBy(slice interface{}, key string, order string)

OrderBy 再map中找到符合规则的数据

func Where

func Where(slice interface{}, name string, value interface{}, isReg ...bool) (idx int, err error)

Where 过滤数据 slice struct数组 name struct value isReg 字符串值时,是否使用正则

func WhereMap

func WhereMap(mp map[string]string, slices interface{}, isReg ...bool) interface{}

WhereMap 查询多个条件过滤 interface 如果有过滤条件将生成新的 数组结构体 如果没有过滤条件 返回原始的数组结构体

Types

type Getter

type Getter func(reflect.Value) []reflect.Value

A Getter is a function which takes a reflect.Value for a slice, and returns a a slice of reflect.Value, e.g. a slice with a reflect.Value for each of the Name fields from a reflect.Value for a slice of a struct type. It is used by the sort functions to identify the elements to sort by.

func FieldGetter

func FieldGetter(name string) Getter

FieldGetter Returns a Getter which gets fields with name from a reflect.Value for a slice of a struct type, returning them as a slice of reflect.Value (one Value for each field in each struct.) Can be used with Sort to sort an []Object by e.g. Object.Name or Object.Date. A runtime panic will occur if the specified field isn't exported.

type Ordering

type Ordering int

Ordering decides the order in which the specified data is sorted.

const (
	Ascending Ordering = iota
	Descending
)

A runtime panic will occur if case-insensitive is used when not sorting by a string type.

func (Ordering) String

func (o Ordering) String() string

type Sorter

type Sorter struct {
	Slice reflect.Value

	Ordering Ordering
	// contains filtered or unexported fields
}

Sorter A reflecting sort.Interface adapter.

func (*Sorter) Len

func (s *Sorter) Len() int

Len Returns the length of the slice being sorted.

func (*Sorter) Sort

func (s *Sorter) Sort() (err error)

Sort the values in s.Slice by retrieving comparison items using s.Getter(s.Slice). A runtime panic will occur if s.Getter is not applicable to s.Slice, or if the values retrieved by s.Getter can't be compared, i.e. are unrecognized types.

func (*Sorter) Swap

func (s *Sorter) Swap(i, j int)

Swap Swaps two indices in the slice being sorted.

Jump to

Keyboard shortcuts

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