typex

package module
v1.25.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: Apache-2.0 Imports: 5 Imported by: 19

README

typex

类型封装

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgsRange added in v1.25.5

func ArgsRange(args Args, handle func(k string, v Value))

ArgsRange 遍历参数收集器

Types

type Args added in v1.25.5

type Args map[string]Value

Args 参数收集器,隐式实现了 Collect[string, Value] 可被json序列化,但是不可被json反序列化,

func (Args) Get added in v1.25.5

func (a Args) Get(k string) Value

func (Args) Put added in v1.25.5

func (a Args) Put(k string, v Value)

func (Args) UnmarshalJSON added in v1.25.5

func (a Args) UnmarshalJSON(data []byte) error

type Bool

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

Bool 布尔值

func NewBool

func NewBool(v ...bool) *Bool

NewBool 创建布尔值

func (*Bool) Bool

func (x *Bool) Bool(def ...bool) bool

func (*Bool) Cover added in v1.25.5

func (x *Bool) Cover(v any)

func (*Bool) Float64

func (x *Bool) Float64(def ...float64) float64

func (*Bool) Int

func (x *Bool) Int(def ...int) int

func (*Bool) Int64

func (x *Bool) Int64(def ...int64) int64

func (*Bool) MarshalJSON

func (x *Bool) MarshalJSON() ([]byte, error)

func (*Bool) String

func (x *Bool) String(def ...string) string

func (*Bool) UnmarshalJSON

func (x *Bool) UnmarshalJSON(bytes []byte) error

func (*Bool) Valid

func (x *Bool) Valid() bool

func (*Bool) Value

func (x *Bool) Value(def ...bool) bool

type Collect added in v1.25.5

type Collect[K comparable, V any] interface {
	Put(k K, v V) // 放入值
	Get(k K) V    // 获取值
}

type CollectAny added in v1.25.5

type CollectAny Collect[string, any] // 任意类型收集器

type CollectString added in v1.25.5

type CollectString Collect[string, string] // 字符串收集器

type CollectValue added in v1.25.5

type CollectValue Collect[string, Value] // 值收集器

type Date

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

func NewDate

func NewDate(v ...time.Time) *Date

func (*Date) MarshalJSON

func (x *Date) MarshalJSON() ([]byte, error)

func (*Date) UnmarshalJSON

func (x *Date) UnmarshalJSON(bytes []byte) error

func (*Date) Valid

func (x *Date) Valid() bool

func (*Date) Value

func (x *Date) Value(def ...time.Time) time.Time

type Enum

type Enum[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Enum 枚举类,实现了Collect[K, V]接口

func NewEnum

func NewEnum[K comparable, V any]() *Enum[K, V]

NewEnum key为comparable类型,value为任意类型

func NewStringEnum

func NewStringEnum[V any]() *Enum[string, V]

NewStringEnum key为string类型,value为任意类型

func (*Enum[K, V]) Add

func (e *Enum[K, V]) Add(k K, v V) *Enum[K, V]

Add 添加枚举值

func (*Enum[K, V]) Clear

func (e *Enum[K, V]) Clear()

Clear 清空枚举值

func (*Enum[K, V]) Exist

func (e *Enum[K, V]) Exist(k K) bool

Exist 判断枚举值是否存在

func (*Enum[K, V]) Get

func (e *Enum[K, V]) Get(k K) V

Get 获取枚举值

func (*Enum[K, V]) Keys

func (e *Enum[K, V]) Keys() []K

Keys 返回枚举值的键列表

func (*Enum[K, V]) Len

func (e *Enum[K, V]) Len() int

Len 返回枚举值数量

func (*Enum[K, V]) Put added in v1.25.5

func (e *Enum[K, V]) Put(k K, v V)

Put 添加枚举值

func (*Enum[K, V]) Range added in v1.25.2

func (e *Enum[K, V]) Range(handle func(k K, v V) bool)

Range 遍历枚举值

func (*Enum[K, V]) RangeWithIndex added in v1.25.2

func (e *Enum[K, V]) RangeWithIndex(handle func(i int, k K, v V) bool)

RangeWithIndex 遍历枚举值,包含下标

func (*Enum[K, V]) Remove

func (e *Enum[K, V]) Remove(k K)

Remove 删除枚举值

func (*Enum[K, V]) Values

func (e *Enum[K, V]) Values() []V

Values 返回枚举值的值列表

type Float64

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

Float64 浮点数值

func NewFloat64

func NewFloat64(t ...float64) *Float64

NewFloat64 创建浮点数值

func (*Float64) Bool

func (x *Float64) Bool(def ...bool) bool

func (*Float64) Cover added in v1.25.5

func (x *Float64) Cover(v any)

func (*Float64) Float64

func (x *Float64) Float64(def ...float64) float64

func (*Float64) Int

func (x *Float64) Int(def ...int) int

func (*Float64) Int64

func (x *Float64) Int64(def ...int64) int64

func (*Float64) MarshalJSON

func (x *Float64) MarshalJSON() ([]byte, error)

func (*Float64) String

func (x *Float64) String(def ...string) string

func (*Float64) UnmarshalJSON

func (x *Float64) UnmarshalJSON(bytes []byte) error

func (*Float64) Valid

func (x *Float64) Valid() bool

func (*Float64) Value

func (x *Float64) Value(def ...float64) float64

type Int

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

Int 整数值

func NewInt

func NewInt(v ...int) *Int

NewInt 创建整数值

func (*Int) Bool

func (x *Int) Bool(def ...bool) bool

func (*Int) Cover added in v1.25.5

func (x *Int) Cover(v any)

func (*Int) Float64

func (x *Int) Float64(def ...float64) float64

func (*Int) Int

func (x *Int) Int(def ...int) int

func (*Int) Int64

func (x *Int) Int64(def ...int64) int64

func (*Int) MarshalJSON

func (x *Int) MarshalJSON() ([]byte, error)

func (*Int) String

func (x *Int) String(def ...string) string

func (*Int) UnmarshalJSON

func (x *Int) UnmarshalJSON(bytes []byte) error

func (*Int) Valid

func (x *Int) Valid() bool

func (*Int) Value

func (x *Int) Value(def ...int) int

type Int64

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

Int64 整数值

func NewInt64

func NewInt64(v ...int64) *Int64

NewInt64 创建整数值

func (*Int64) Bool

func (x *Int64) Bool(def ...bool) bool

func (*Int64) Cover added in v1.25.5

func (x *Int64) Cover(v any)

func (*Int64) Float64

func (x *Int64) Float64(def ...float64) float64

func (*Int64) Int

func (x *Int64) Int(def ...int) int

func (*Int64) Int64

func (x *Int64) Int64(def ...int64) int64

func (*Int64) MarshalJSON

func (x *Int64) MarshalJSON() ([]byte, error)

func (*Int64) String

func (x *Int64) String(def ...string) string

func (*Int64) UnmarshalJSON

func (x *Int64) UnmarshalJSON(bytes []byte) error

func (*Int64) Valid

func (x *Int64) Valid() bool

func (*Int64) Value

func (x *Int64) Value(def ...int64) int64
type Link[T any] struct {
	// contains filtered or unexported fields
}
func NewLink[T any](value T) *Link[T]

NewLink 创建链表

func (*Link[T]) Append added in v1.25.3

func (list *Link[T]) Append(value T) *Link[T]

Append 追加节点

func (*Link[T]) GetHead added in v1.25.3

func (list *Link[T]) GetHead() (T, bool)

GetHead 获取头节点数据

func (*Link[T]) GetTail added in v1.25.3

func (list *Link[T]) GetTail() (T, bool)

GetTail 获取尾节点数据

func (*Link[T]) Remove added in v1.25.3

func (list *Link[T]) Remove() *Link[T]

Remove 删除尾节点

func (*Link[T]) Size added in v1.25.3

func (list *Link[T]) Size() int

type String

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

String 字符串值

func NewString

func NewString(v ...string) *String

NewString 创建字符串值

func (*String) Bool

func (x *String) Bool(def ...bool) bool

func (*String) Cover added in v1.25.5

func (x *String) Cover(v any)

func (*String) Float64

func (x *String) Float64(def ...float64) float64

func (*String) Int

func (x *String) Int(def ...int) int

func (*String) Int64

func (x *String) Int64(def ...int64) int64

func (*String) MarshalJSON

func (x *String) MarshalJSON() ([]byte, error)

func (*String) String

func (x *String) String(def ...string) string

func (*String) UnmarshalJSON

func (x *String) UnmarshalJSON(bytes []byte) error

func (*String) Valid

func (x *String) Valid() bool

func (*String) Value

func (x *String) Value(def ...string) string

type Time

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

func NewTime

func NewTime(v ...time.Time) *Time

func (*Time) MarshalJSON

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

func (*Time) UnmarshalJSON

func (x *Time) UnmarshalJSON(bytes []byte) error

func (*Time) Valid

func (x *Time) Valid() bool

func (*Time) Value

func (x *Time) Value(def ...time.Time) time.Time

type TreeNode

type TreeNode[T any] struct {
	Id    string         `json:"id"`
	Pid   string         `json:"pid"`
	Data  T              `json:"data"`
	Child []*TreeNode[T] `json:"child"`
}

TreeNode 树形节点

func Convert2Tree

func Convert2Tree[N treeNode](list []N, root string) []*TreeNode[N]

Convert2Tree 平铺数组转为树形结构

type Value

type Value interface {
	Valid() bool                    // 是否有效
	Cover(v any)                    // 覆盖值
	String(def ...string) string    // 转为字符串,若无效则返回默认值
	Int(def ...int) int             // 转为整数,若无效则返回默认值
	Int64(def ...int64) int64       // 转为整数,若无效则返回默认值
	Float64(def ...float64) float64 // 转为浮点数,若无效则返回默认值
	Bool(def ...bool) bool          // 转为布尔值,若无效则返回默认值
	MarshalJSON() ([]byte, error)   // 序列化为json
	UnmarshalJSON([]byte) error     // 从json反序列化
}

Value 任意值

func NewValue

func NewValue(v any) Value

NewValue 创建任意值

type Zero

type Zero struct{}

Zero 零值

func NewZero added in v1.25.4

func NewZero() *Zero

NewZero 创建零值

func (*Zero) Bool

func (z *Zero) Bool(...bool) bool

func (*Zero) Cover added in v1.25.5

func (z *Zero) Cover(_ any)

func (*Zero) Float64

func (z *Zero) Float64(...float64) float64

func (*Zero) Int

func (z *Zero) Int(...int) int

func (*Zero) Int64

func (z *Zero) Int64(...int64) int64

func (*Zero) MarshalJSON added in v1.25.5

func (z *Zero) MarshalJSON() ([]byte, error)

func (*Zero) String

func (z *Zero) String(...string) string

func (*Zero) UnmarshalJSON added in v1.25.5

func (z *Zero) UnmarshalJSON(_ []byte) error

func (*Zero) Valid

func (z *Zero) Valid() bool

Jump to

Keyboard shortcuts

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