Documentation
¶
Index ¶
- type INullable
- type Nullable
- func (n *Nullable[T]) Get() (T, bool)
- func (n *Nullable[T]) GetOrElse(defaultVal T) T
- func (n *Nullable[T]) IsNotNull() bool
- func (n *Nullable[T]) IsNull() bool
- func (n *Nullable[T]) IsZero() bool
- func (n *Nullable[T]) MarshalJSON() ([]byte, error)
- func (n *Nullable[T]) Scan(src any) error
- func (n *Nullable[T]) Set(val T)
- func (n *Nullable[T]) SetNull()
- func (n *Nullable[T]) String() string
- func (n *Nullable[T]) UnmarshalJSON(data []byte) error
- func (n *Nullable[T]) Value() (driver.Value, error)
- type Queue
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type INullable ¶
type INullable[T any] interface { // 实现了数据库驱动的 Value 扫描功能,允许将数据库中的值转换为Nullable类型 sql.Scanner // 实现了数据库驱动的 Value 接口,用于将Nullable类型转换为数据库驱动期望的值 driver.Valuer // 实现了json.Marshaler接口,用于将Nullable类型值转换为JSON格式 json.Marshaler // 实现了json.Unmarshaler接口,用于将JSON格式的数据转换为Nullable类型值 json.Unmarshaler fmt.Stringer // // 返回值: // bool: 如果当前对象为零值,则返回true;否则返回false。 IsZero() bool // 用于获取Nullable类型内部存储的值 Get() (T, bool) // 用于获取Nullable类型内部存储的值,如果未设置,则返回默认值 GetOrElse(defaultVal T) T // 用于判断 Nullable 类型内部的值是否未设置 IsNull() bool // 用于判断 Nullable 类型内部的值是否已设置 IsNotNull() bool // 用于设置某个类型的值 Set(val T) // 用于将值设置为NULL SetNull() }
INullable 是一个泛型接口,表示可以表示任何类型的 NULL 值
type Nullable ¶
func (*Nullable[T]) GetOrElse ¶
func (n *Nullable[T]) GetOrElse(defaultVal T) T
GetOrElse 获取值,如果无效则返回默认值
func (*Nullable[T]) IsZero ¶
IsZero 判断 nullable 类型的值是否为零值。 此方法主要用于检查类型 T 的值是否被设置(即是否存在)。 返回值为布尔类型,如果值未被设置,则返回 true,否则返回 false。
func (*Nullable[T]) MarshalJSON ¶
MarshalJSON 实现 json.Marshaler 接口
func (*Nullable[T]) UnmarshalJSON ¶
UnmarshalJSON 实现 json.Unmarshaler 接口
type Queue ¶
type Queue[T any] interface { //入队 Enqueue(value T) //出队 Dequeue() (T, bool) //判空 IsEmpty() bool //迭代器 (Go 1.23+) Iter() iter.Seq[T] }
线程安全队列
Source Files
¶
- nullable.go
- queue.go
- set.go
Click to show internal directories.
Click to hide internal directories.