x

package
v0.0.0-...-087ca59 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertPanic

func AssertPanic(t *testing.T, f func(), msg interface{})

func CanConvert

func CanConvert[FromType any, ToType any]() bool

CanConvert returns true if FromType can be converted to ToType.

func Float32

func Float32() float32

func Float64

func Float64() float64

func Get

func Get(url string, headers map[string]string, result any) error

func HasField

func HasField(t reflect.Type, name string) bool

func Int63

func Int63() int64

func Intn

func Intn(n int) int

func IsSortDesc

func IsSortDesc(sort string) bool

func Letters

func Letters(n int) string

func Post

func Post(url, contentType string, body any, result any) error

func PostUrlForm

func PostUrlForm(path string, body map[string]string, result any) error

func Ptr

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

func Ptrs

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

func ToJsonMapString

func ToJsonMapString(v any) map[string]string

func ToUint

func ToUint(s string) uint64

func TypeOf

func TypeOf[T any]() reflect.Type

func Zero

func Zero[T any]() T

Types

type BigInt

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

func NewBigInt

func NewBigInt(bigint *big.Int) BigInt

func ParseBigInt

func ParseBigInt(v string) BigInt

func (*BigInt) Int

func (bi *BigInt) Int() *big.Int

func (*BigInt) MarshalBSON

func (bi *BigInt) MarshalBSON() ([]byte, error)

func (*BigInt) MarshalJSON

func (bi *BigInt) MarshalJSON() ([]byte, error)

func (*BigInt) UnmarshalBSON

func (bi *BigInt) UnmarshalBSON(data []byte) error

func (*BigInt) UnmarshalJSON

func (bi *BigInt) UnmarshalJSON(data []byte) error

type ID

type ID = int64

type IdGenerator

type IdGenerator[T comparable] interface {
	Create() T
}

func NewNumberIdGenerator

func NewNumberIdGenerator[T ~int64]() *IdGenerator[T]

func NewStringIdGenerator

func NewStringIdGenerator[T ~string]() *IdGenerator[T]

type IdGeneratorOptions

type IdGeneratorOptions struct {
	WorkerId          uint16
	WorkerIdBitLength byte // 机器码位长,默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22)
	SeqBitLength      byte // 序列数位长,默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22)
}

type Int64IdGenerator

type Int64IdGenerator[T ~int64] struct {
}

func (*Int64IdGenerator[T]) Create

func (u *Int64IdGenerator[T]) Create() T

type NullableTime

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

NullableTime is a wrapper of time.Time, which can be marshaled to JSON as RFC3339 format. It can be used as a nullable time.Time field. empty value is zero time value is null or time

func (*NullableTime) Format

func (t *NullableTime) Format(layout string) string

func (*NullableTime) IsNil

func (t *NullableTime) IsNil() bool

func (*NullableTime) IsZero

func (t *NullableTime) IsZero() bool

func (NullableTime) MarshalJSON

func (t NullableTime) MarshalJSON() ([]byte, error)

func (*NullableTime) SetNil

func (t *NullableTime) SetNil()

func (*NullableTime) SetTime

func (t *NullableTime) SetTime(time time.Time)

func (*NullableTime) String

func (t *NullableTime) String() string

func (*NullableTime) Time

func (t *NullableTime) Time() *time.Time

func (*NullableTime) UnmarshalJSON

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

type PageAndSort

type PageAndSort struct {
	PageParam `json:",inline"` // 页码, 从1开始
	Sort      string           `json:"sort"` // 排序字段, 例如: -createdAt, +updatedAt
}

func NewPageAndSort

func NewPageAndSort(page, pageSize int64, sort string) *PageAndSort

NewPageAndSort new page and sort

func NewPageAndSortWithId

func NewPageAndSortWithId(includedId any, pageSize int64, sort string) *PageAndSort

func PageLimit

func PageLimit(limit int) *PageAndSort

func (*PageAndSort) Copy

func (p *PageAndSort) Copy() *PageAndSort

func (*PageAndSort) IsDesc

func (p *PageAndSort) IsDesc() bool

IsDesc is sorted by desc

type PageParam

type PageParam struct {
	Page         int64 `json:"page"`         // 页码, 从1开始
	PageSize     int64 `json:"pageSize"`     // 每页大小
	IncludeTotal bool  `json:"includeTotal"` // 是否包含总数
	IncludedId   any   `json:"id"`           // 包含指定Id的数据,用于分页查询,这时候不需要传入page
}

func NewPageParam

func NewPageParam(page, pageSize int64) *PageParam

NewPageParam new page param

func PageParamWithId

func PageParamWithId(includedId any, limit int64) *PageParam

func (*PageParam) Limit

func (p *PageParam) Limit() int64

func (*PageParam) Skip

func (p *PageParam) Skip() int64

type PagedResult

type PagedResult[T any] struct {
	Total   int64 `json:"total"`
	Data    []T   `json:"data"`
	HasMore bool  `json:"hasMore"`
	Page    int64 `json:"page"`
}

type Set

type Set[T comparable] map[T]struct{}

Set is a set of items. It is implemented as a map[T]struct{}.

func NewSet

func NewSet[T comparable](items ...T) Set[T]

func (Set[T]) Contains

func (set Set[T]) Contains(item T) bool

func (Set[T]) Delete

func (set Set[T]) Delete(item T)

func (Set[T]) Len

func (set Set[T]) Len() int

func (Set[T]) Set

func (set Set[T]) Set(item T)

func (Set[T]) ToSlice

func (set Set[T]) ToSlice() []T

type StringID

type StringID = string

type StringIdGenerator

type StringIdGenerator[T ~string] struct {
}

func (*StringIdGenerator[T]) Create

func (u *StringIdGenerator[T]) Create() T

Jump to

Keyboard shortcuts

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