util

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 23 Imported by: 5

Documentation

Index

Constants

View Source
const CSTLayout = "2006-01-02 15:04:05"

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(data []byte, key []byte) ([]byte, error)

AesDecrypt 解密

func AesEncrypt

func AesEncrypt(data []byte, key []byte) ([]byte, error)

AesEncrypt 加密

func CryptoByMd5

func CryptoByMd5(data []byte) []byte

func DecryptByAes

func DecryptByAes(data, pwdKey string) (string, error)

DecryptByAes Aes 解密

func EncryptByAes

func EncryptByAes(data, pwdKey string) (string, error)

EncryptByAes Aes加密 后 base64 再加

func ExistIntArray

func ExistIntArray(val int, array []int) bool

ExistIntArray 是否存在数组中

func ExtractSummary

func ExtractSummary(content string) string

ExtractSummary 抽取摘要

func ExtractTelephone

func ExtractTelephone(val string) (ret string)

func GetAbove added in v1.2.6

func GetAbove(val string) interface{}

func GetBelow added in v1.2.6

func GetBelow(val string) interface{}

func GetEqual added in v1.2.6

func GetEqual(val string) interface{}

func GetIn added in v1.2.6

func GetIn(val string) interface{}

func GetLike added in v1.2.6

func GetLike(val string) interface{}

func GetNotEqual added in v1.2.6

func GetNotEqual(val string) interface{}

func GetNotIn added in v1.2.6

func GetNotIn(val string) interface{}

func IntArray2Str

func IntArray2Str(ids []int) string

IntArray2Str 数字数组转字符串

func LoadConfig

func LoadConfig(filePath string, ptr interface{}) (err error)

func MarshalString

func MarshalString(val interface{}) string

func RandomAlphaOrNumeric

func RandomAlphaOrNumeric(count uint, letters, numbers bool) string

RandomAlphaOrNumeric Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.

Param count - the length of random string to create Param letters - if true, generated string will include

alphabetic characters

Param numbers - if true, generated string will include

numeric characters

func RandomAlphabetic

func RandomAlphabetic(count uint) string

RandomAlphabetic Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of alphabetic characters.

func RandomAlphanumeric

func RandomAlphanumeric(count uint) string

RandomAlphanumeric Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of alpha-numeric characters.

func RandomAscII

func RandomAscII(count uint) string

RandomAscII Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of characters whose ASCII value is between 32 and 126 (inclusive).

func RandomIdentifyCode

func RandomIdentifyCode() string

RandomIdentifyCode 生成6位随机数验证码

func RandomNumeric

func RandomNumeric(count uint) string

RandomNumeric Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of numeric characters.

func RandomSpec0

func RandomSpec0(count uint, start, end int, letters, numbers bool,
	chars []rune, rand *rand.Rand) string

RandomSpec0 Creates a random string based on a variety of options, using supplied source of randomness.

If start and end are both 0, start and end are set to ' ' and 'z', the ASCII printable characters, will be used, unless letters and numbers are both false, in which case, start and end are set to 0 and math.MaxInt32.

If set is not nil, characters between start and end are chosen.

This method accepts a user-supplied rand.Rand instance to use as a source of randomness. By seeding a single rand.Rand instance with a fixed seed and using it for each call, the same random sequence of strings can be generated repeatedly and predictably.

func RandomSpec1

func RandomSpec1(count uint, start, end int, letters, numbers bool) string

RandomSpec1 Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.

Param count - the length of random string to create Param start - the position in set of chars to start at Param end - the position in set of chars to end before Param letters - if true, generated string will include

alphabetic characters

Param numbers - if true, generated string will include

numeric characters

func RandomString

func RandomString(count uint) string

RandomString RandomString

func RandomStringSpec0

func RandomStringSpec0(count uint, set []rune) string

RandomStringSpec0 RandomStringSpec0

func RandomStringSpec1

func RandomStringSpec1(count uint, set string) string

RandomStringSpec1 RandomStringSpec1

func SameIntArray

func SameIntArray(val []int, array []int) bool

SameIntArray 是否存在数组中

func SaveConfig

func SaveConfig(filePath string, ptr interface{}) (err error)

func Str2IntArray

func Str2IntArray(str string) ([]int, bool)

Str2IntArray 字符串转换成数字数组

func UnmarshalString

func UnmarshalString(val string) interface{}

func ValidateFunc

func ValidateFunc(fun interface{})

ValidateFunc 校验是否是函数

func ValidatePtr

func ValidatePtr(ptr interface{})

ValidatePtr 校验是否是指针

Types

type CatalogObjectRegistry

type CatalogObjectRegistry interface {
	Put(id, catalog string, object interface{})
	Get(id, catalog string) interface{}
	Sort(catalog string, sorter ObjectSorter)
	FetchList(catalog string, pageFilter *Pagination) *ObjectList
	Filter(catalog string, filter Filter, pageFilter *Pagination) *ObjectList
	Remove(id, catalog string)
}

CatalogObjectRegistry catalog object registry

func NewCatalogRegistry

func NewCatalogRegistry() CatalogObjectRegistry

NewCatalogRegistry create new catalog registry

type ContentFilter

type ContentFilter struct {
	Pagination *Pagination `json:"pagination"`
	ParamItems *ParamItems `json:"params"`
}

ContentFilter 过滤器

func NewFilter

func NewFilter(name, pkgPath string) *ContentFilter

NewFilter new filter

func (*ContentFilter) Above

func (s *ContentFilter) Above(key string, value interface{})

func (*ContentFilter) Below

func (s *ContentFilter) Below(key string, value interface{})

func (*ContentFilter) Decode

func (s *ContentFilter) Decode(request *http.Request) bool

Decode 内容过滤器

func (*ContentFilter) Encode

func (s *ContentFilter) Encode(vals url.Values) url.Values

Encode encode filter

func (*ContentFilter) Equal

func (s *ContentFilter) Equal(key string, value interface{})

func (*ContentFilter) Get

func (s *ContentFilter) Get(key string) (val string, ok bool)

func (*ContentFilter) GetName added in v1.3.1

func (s *ContentFilter) GetName() string

func (*ContentFilter) GetPkgPath added in v1.3.1

func (s *ContentFilter) GetPkgPath() string

func (*ContentFilter) In

func (s *ContentFilter) In(key string, value interface{})

func (*ContentFilter) Like

func (s *ContentFilter) Like(key string, value interface{})

func (*ContentFilter) NotEqual

func (s *ContentFilter) NotEqual(key string, value interface{})

func (*ContentFilter) NotIn

func (s *ContentFilter) NotIn(key string, value interface{})

func (*ContentFilter) Remove

func (s *ContentFilter) Remove(key string)

func (*ContentFilter) Set

func (s *ContentFilter) Set(key string, value interface{})

type Filter

type Filter interface {
	Filter(val interface{}) bool
}

Filter value filter

type ObjectList

type ObjectList []interface{}

ObjectList object list

type ObjectRegistry

type ObjectRegistry interface {
	Put(id string, object interface{})
	Get(id string) interface{}
	Sort(sorter ObjectSorter)
	FetchList(pageFilter *Pagination) *ObjectList
	Filter(filter Filter, pageFilter *Pagination) *ObjectList
	Remove(id string)
}

ObjectRegistry object 仓库

func NewRegistry

func NewRegistry() ObjectRegistry

NewRegistry create new Registry

type ObjectSorter

type ObjectSorter interface {
	Less(left, right interface{}) bool
}

ObjectSorter help object slice sort

type Pagination

type Pagination struct {
	// 单页条目数
	PageSize int `json:"pageSize"`
	// 页码
	PageNum int `json:"pageNum"`
}

Pagination 页面过滤器

func DefaultPagination

func DefaultPagination() *Pagination

func NewPagination

func NewPagination(defaultSize, defaultNum int) *Pagination

func (*Pagination) Decode

func (s *Pagination) Decode(request *http.Request) bool

Decode 从request里解析PageFilter

func (*Pagination) Encode

func (s *Pagination) Encode(vals url.Values) url.Values

Encode encode url.Values

type ParamItems

type ParamItems struct {
	Name    string            `json:"name"`
	PkgPath string            `json:"pkgPath"`
	Items   map[string]string `json:"items"`
}

ParamItems contentFilter

func (*ParamItems) Decode

func (s *ParamItems) Decode(request *http.Request) bool

Decode 解析内容过滤值

func (*ParamItems) Encode

func (s *ParamItems) Encode(vals url.Values) url.Values

Encode ParamItems

func (*ParamItems) GetAbove

func (s *ParamItems) GetAbove(key string) interface{}

func (*ParamItems) GetBelow

func (s *ParamItems) GetBelow(key string) interface{}

func (*ParamItems) GetEqual

func (s *ParamItems) GetEqual(key string) interface{}

func (*ParamItems) GetIn

func (s *ParamItems) GetIn(key string) interface{}

func (*ParamItems) GetLike

func (s *ParamItems) GetLike(key string) interface{}

func (*ParamItems) GetNotEqual

func (s *ParamItems) GetNotEqual(key string) interface{}

func (*ParamItems) GetNotIn

func (s *ParamItems) GetNotIn(key string) interface{}

func (*ParamItems) IsAbove

func (s *ParamItems) IsAbove(key string) bool

func (*ParamItems) IsBelow

func (s *ParamItems) IsBelow(key string) bool

func (*ParamItems) IsEqual

func (s *ParamItems) IsEqual(key string) bool

func (*ParamItems) IsIn

func (s *ParamItems) IsIn(key string) bool

func (*ParamItems) IsLike

func (s *ParamItems) IsLike(key string) bool

func (*ParamItems) IsNotEqual

func (s *ParamItems) IsNotEqual(key string) bool

func (*ParamItems) IsNotIn

func (s *ParamItems) IsNotIn(key string) bool

type SortFilter

type SortFilter struct {
	// true:升序,false:降序
	AscFlag bool `json:"ascFlag"`
	// 排序字段
	FieldName string `json:"fieldName"`
}

SortFilter 页面过滤器

func NewSortFilter

func NewSortFilter(name string, ascFlag bool) *SortFilter

func (*SortFilter) AscSort

func (s *SortFilter) AscSort() bool

func (*SortFilter) Name

func (s *SortFilter) Name() string

Name return name

type SortHelper

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

SortHelper sortHelper

func NewSortHelper

func NewSortHelper(objList []interface{}, sorter ObjectSorter) *SortHelper

NewSortHelper new SortHelper

func (SortHelper) Len

func (s SortHelper) Len() int

func (SortHelper) Less

func (s SortHelper) Less(i, j int) bool

func (SortHelper) Swap

func (s SortHelper) Swap(i, j int)

type StringSet

type StringSet []string

func (StringSet) Add

func (s StringSet) Add(val string) StringSet

func (StringSet) Empty

func (s StringSet) Empty() bool

func (StringSet) Remove

func (s StringSet) Remove(val string) StringSet

type Validator

type Validator interface {
	Validate(value interface{}) error
}

func NewFormValidator

func NewFormValidator() Validator

Jump to

Keyboard shortcuts

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