types

package
v1.1.26 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrValidatePassword = status.Error(http.StatusUnauthorized, "密码错误")

ErrValidatePassword 密码错误

Functions

func Contains added in v1.0.0

func Contains[T comparable](list []T, v T) bool

Contains 是否包含

func ContainsOf added in v1.0.0

func ContainsOf[T any](list []T, f func(T) bool) bool

ContainsOf 是否包含

func ExtractPointerOr added in v1.0.0

func ExtractPointerOr[T any](value any, fallback ...T) T

ExtractPointerOr 解包多层指针, 如果为nil则返回指定的默认值(没有指定,则返回go默认值), 否则返回值本身

func Filter added in v1.0.0

func Filter[T any](list []T, f func(T) bool) []T

Filter 过滤

func Index added in v1.0.0

func Index[T comparable](list []T, v T) int

Index 查找元素的索引

func IndexOf added in v1.0.0

func IndexOf[T any](list []T, f func(T) bool) int

IndexOf 查找元素的索引

func IsNil

func IsNil(i interface{}) bool

IsNil 判断是否为nil

func JSONToMap added in v1.1.22

func JSONToMap(jsonStr string) (map[string]interface{}, error)

JSONToMap json转map

func Limit added in v1.1.0

func Limit(t any, limit int) any

func MD5 added in v1.0.2

func MD5(str string) string

MD5 returns the MD5 checksum of the data.

func MapsMerge added in v1.0.0

func MapsMerge[K comparable, V any](ms ...map[K]V) map[K]V

MapsMerge 合并多个map

func Marshal added in v1.0.2

func Marshal(v any) ([]byte, error)

Marshal marshals the given value into a byte slice.

func MergeSlice added in v1.0.0

func MergeSlice[T any](slices ...[]T) []T

MergeSlice 合并切片

func MergeSliceWithUnique added in v1.0.0

func MergeSliceWithUnique[T comparable](slices ...[]T) []T

MergeSliceWithUnique 合并切片,并去重

func Of added in v1.0.0

func Of[T any](v T) *T

Of 获取对象指针

func RegisterCodec added in v1.0.2

func RegisterCodec(codec encoding.Codec)

RegisterCodec registers a codec with the default marshal and unmarshal functions.

func SetDefaultMarshalFn added in v1.0.2

func SetDefaultMarshalFn(fn func(v any) ([]byte, error))

SetDefaultMarshalFn sets the default marshal function.

func SetDefaultUnmarshalFn added in v1.0.2

func SetDefaultUnmarshalFn(fn func(data []byte, v any) error)

SetDefaultUnmarshalFn sets the default unmarshal function.

func SliceTo added in v1.0.0

func SliceTo[T, R any](s []T, call func(T) R) []R

SliceTo 将slice转换为指定类型

func SliceToWithFilter added in v1.0.0

func SliceToWithFilter[T, R any](s []T, call func(T) (R, bool)) []R

SliceToWithFilter 将slice转换为指定类型,并过滤掉指定的值

func SliceUnique added in v1.0.0

func SliceUnique[T comparable](s []T) []T

SliceUnique 切片去重

func SlicesHasDuplicates added in v1.0.0

func SlicesHasDuplicates[T any, R comparable](arr []T, keyFunc func(T) R) bool

SlicesHasDuplicates 是否有重复元素

func SlicesIntersection added in v1.0.0

func SlicesIntersection[T compare](slice1, slice2 []T) []T

SlicesIntersection 求交集

func Ternary added in v1.0.2

func Ternary[T any](condition bool, trueVal, falseVal T) T

Ternary returns trueVal if condition is true, falseVal otherwise.

func TextIsNull added in v1.0.0

func TextIsNull(text string) bool

TextIsNull 判断字符串是否为空

func TextJoin added in v1.1.0

func TextJoin(s ...string) string

TextJoin 拼接字符串

func TextJoinByBytes added in v1.1.0

func TextJoinByBytes(s ...[]byte) string

TextJoinByBytes 拼接字符串

func TextJoinByBytesToBytes added in v1.1.0

func TextJoinByBytesToBytes(ss ...[]byte) []byte

TextJoinByBytesToBytes 拼接字符串

func TextJoinByStringer added in v1.1.0

func TextJoinByStringer(s ...fmt.Stringer) string

TextJoinByStringer 拼接字符串

func TextJoinByStringerToBytes added in v1.1.0

func TextJoinByStringerToBytes(ss ...fmt.Stringer) []byte

TextJoinByStringerToBytes 拼接字符串

func TextJoinToBytes added in v1.1.0

func TextJoinToBytes(ss ...string) []byte

TextJoinToBytes 拼接字符串

func To added in v1.0.0

func To[T, R any](list []T, f func(T) R) []R

To 转换为其他类型

func ToFilter added in v1.0.0

func ToFilter[T, R any](list []T, f func(T) (R, bool)) []R

ToFilter 过滤

func ToMap added in v1.0.0

func ToMap[T any, R comparable](list []T, f func(T) R) map[R]T

ToMap 切片转map

func Unmarshal added in v1.0.2

func Unmarshal(data []byte, v any) error

Unmarshal unmarshals the given byte slice into the given value.

func UnwrapOr added in v1.0.0

func UnwrapOr[T any](p *T, fallback ...T) T

UnwrapOr 解包指针, 如果为nil则返回指定的默认值(没有指定,则返回go默认值), 否则返回值本身

func WithPageQuery added in v1.0.0

func WithPageQuery[T any, Q PageQuery[T]](q Q, page Pagination) (T, error)

WithPageQuery 分页查询

Types

type Decoder added in v1.0.2

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

Decoder is a generic decoder that can be used to decode values.

func NewDecoder added in v1.0.2

func NewDecoder(r io.Reader, opts ...DecoderOption) *Decoder

NewDecoder creates a new decoder with the given options.

func (*Decoder) Decode added in v1.0.2

func (d *Decoder) Decode(v any) error

type DecoderOption added in v1.0.2

type DecoderOption func(*Decoder)

DecoderOption is a function that can be used to configure a decoder.

type Duration added in v1.0.0

type Duration struct {
	Duration *durationpb.Duration
}

Duration 包装后的时间类型

func NewDuration added in v1.0.0

func NewDuration(dur *durationpb.Duration) *Duration

NewDuration 创建一个 Duration

func (*Duration) CronTime added in v1.0.0

func (d *Duration) CronTime() string

CronTime 定义一个时间间隔,单位为秒

func (*Duration) GetDuration added in v1.0.0

func (d *Duration) GetDuration() *durationpb.Duration

GetDuration 获取 Duration

func (*Duration) MarshalJSON added in v1.1.0

func (d *Duration) MarshalJSON() ([]byte, error)

func (*Duration) Scan added in v1.0.0

func (d *Duration) Scan(src any) error

Scan 现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (*Duration) String added in v1.1.0

func (d *Duration) String() string

func (*Duration) UnmarshalJSON added in v1.1.0

func (d *Duration) UnmarshalJSON(data []byte) error

func (*Duration) Value added in v1.0.0

func (d *Duration) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value

type IPaginationReq added in v1.0.2

type IPaginationReq interface {
	GetPageNum() int32
	GetPageSize() int32
}

type Limiter added in v1.1.0

type Limiter[T any] interface {
	Limit(limit int) T
}

type PageQuery added in v1.0.0

type PageQuery[T any] interface {
	Limit(limit int) T
	Offset(offset int) T
	Where(conds ...gen.Condition) T
	Count() (count int64, err error)
}

PageQuery 分页查询

type Pagination added in v1.0.0

type Pagination interface {
	IPaginationReq
	GetTotal() int64
	SetTotal(total int64)
}

Pagination 分页器

func NewPage added in v1.0.0

func NewPage(pageNum, pageSize int32) Pagination

NewPage 创建一个分页器

func NewPagination added in v1.0.0

func NewPagination(page IPaginationReq) Pagination

NewPagination 获取分页器

type Password added in v1.0.0

type Password interface {
	GetValue() string
	GetSalt() string
	fmt.Stringer
	Validate(checkPass string) error
}

Password 密码

func NewPassword added in v1.0.0

func NewPassword(values ...string) Password

NewPassword 创建密码

type Slice added in v1.0.2

type Slice[T comparable] []T

func NewUint32SlicePointer added in v1.0.2

func NewUint32SlicePointer(uint32Slice []uint32) *Slice[uint32]

NewUint32SlicePointer 创建 *Slice[uint32]

func (*Slice[T]) Scan added in v1.0.2

func (s *Slice[T]) Scan(src any) (err error)

Scan 实现 sql.Scanner 接口

func (Slice[T]) ToSlice added in v1.0.2

func (s Slice[T]) ToSlice() []T

ToSlice 转换为slice

func (Slice[T]) Value added in v1.0.2

func (s Slice[T]) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口

type Time added in v1.0.0

type Time struct {
	time.Time
}

Time 包装后的时间类型

func NewTime added in v1.0.0

func NewTime(t time.Time) *Time

NewTime 创建一个 Time

func NewTimeByString added in v1.0.0

func NewTimeByString(s string, layout ...string) *Time

NewTimeByString 从字符串创建一个 Time

func NewTimeByUnix added in v1.0.0

func NewTimeByUnix(unix int64) *Time

NewTimeByUnix 从unix 创建一个 Time

func (*Time) MarshalJSON added in v1.1.0

func (t *Time) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口

func (*Time) Scan added in v1.0.0

func (t *Time) Scan(value interface{}) error

Scan 现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (*Time) String added in v1.0.0

func (t *Time) String() string

String implements Stringer interface

func (*Time) Unix added in v1.0.0

func (t *Time) Unix() int64

Unix implements Unix interface

func (*Time) UnmarshalJSON added in v1.1.0

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口

func (*Time) Value added in v1.0.0

func (t *Time) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value

Jump to

Keyboard shortcuts

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