typex

package module
v1.25.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: Apache-2.0 Imports: 4 Imported by: 19

README

typex

类型封装

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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) 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 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 枚举类

func NewEnum

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

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

func NewIntEnum

func NewIntEnum[T any]() *Enum[int, T]

NewIntEnum key为int类型,value为任意类型

func NewStringEnum

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

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

func (*Enum[K, V]) Add

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

func (*Enum[K, V]) Clear

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

func (*Enum[K, V]) Exist

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

func (*Enum[K, V]) Get

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

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

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

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

Range 遍历枚举值

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

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

RangeWithIndex 遍历枚举值

func (*Enum[K, V]) Remove

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

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) 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) 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) 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 Node

type Node interface {
	GetID() string
	GetPID() string
}

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) 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 Node](list []N, root string) []*TreeNode[N]

Convert2Tree 平铺数组转为树形结构

type Trie

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

Trie Trie树

func NewTrie

func NewTrie() *Trie

NewTrie 创建前缀树

func (*Trie) Add

func (t *Trie) Add(sentence string, weight ...int)

Add 添加句子

func (*Trie) AddMap

func (t *Trie) AddMap(sentences map[string]int)

AddMap 添加

func (*Trie) AddSlice

func (t *Trie) AddSlice(sentences []string)

AddSlice 添加文本

func (*Trie) Check

func (t *Trie) Check(sentence string) (bool, int)

Check 判断是否包含

func (*Trie) Mask

func (t *Trie) Mask(sentence string) string

Mask 文本打码

func (*Trie) Update

func (t *Trie) Update(word string, weight int)

Update 更新权重

type Unique added in v1.25.4

type Unique interface {
	GetKey() string // 获取唯一主键
}

Unique 唯一主键接口

type Value

type Value interface {
	Valid() bool                    // 是否有效
	String(def ...string) string    // 转为字符串,若无效则返回默认值
	Int(def ...int) int             // 转为整数,若无效则返回默认值
	Int64(def ...int64) int64       // 转为整数,若无效则返回默认值
	Float64(def ...float64) float64 // 转为浮点数,若无效则返回默认值
	Bool(def ...bool) bool          // 转为布尔值,若无效则返回默认值
}

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) 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) String

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

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