meta

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ZeroAsNull = true

0 是否当成 NULL 处理

View Source
const ZeroID = ID(0)

0 ID 常量

Variables

This section is empty.

Functions

This section is empty.

Types

type Birthday

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

func NewBirthday

func NewBirthday(day string) Birthday

NewBirthday 创建一个新的 Birthday 实例

func (Birthday) Day

func (b Birthday) Day() string

Day 返回生日字符串,格式为 YYYY-MM-DD

func (Birthday) Equal

func (b Birthday) Equal(other Birthday) bool

Equal 比较两个 Birthday 是否相等

func (Birthday) IsEmpty

func (b Birthday) IsEmpty() bool

IsEmpty 判断生日是否为空

func (*Birthday) Scan

func (b *Birthday) Scan(src interface{}) error

Scan 实现 sql.Scanner 接口,从数据库读取值

func (Birthday) String

func (b Birthday) String() string

String 返回生日字符串

func (Birthday) Value

func (b Birthday) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,返回数据库存储值

type Email

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

Email 邮箱值对象

func NewEmail

func NewEmail(raw string) (Email, error)

NewEmail 解析并创建 Email 实例

func (Email) Address

func (e Email) Address() string

func (Email) DomainASCII

func (e Email) DomainASCII() (string, error)

func (Email) Equal

func (e Email) Equal(o Email) bool

两边都已规范化,直接字符串相等即可

func (Email) IsEmpty

func (e Email) IsEmpty() bool

func (Email) LocalPart

func (e Email) LocalPart() (string, error)

取本地部分与域(域为 ASCII 小写)

func (Email) MarshalJSON

func (e Email) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口,返回 JSON 编码值

func (*Email) Scan

func (e *Email) Scan(src any) error

Scan 实现 sql.Scanner 接口,从数据库读取值

func (Email) String

func (e Email) String() string

func (*Email) UnmarshalJSON

func (e *Email) UnmarshalJSON(b []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口,解析 JSON 编码值

func (Email) Value

func (e Email) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,返回数据库存储值

type Gender

type Gender uint8
const (
	GenderMale   Gender = 1 // 男性
	GenderFemale Gender = 2 // 女性
	GenderOther  Gender = 0 // 其他
)

func NewGender

func NewGender(g uint8) Gender

NewGender 创建性别

func (Gender) String

func (g Gender) String() string

String 获取性别字符串

func (Gender) Value

func (g Gender) Value() uint8

Value 获取性别值

type Height

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

Height 表示以 0.1 单位存储的身高(单位:厘米,例如 170.5cm -> 1705)

func NewHeightFromFloat

func NewHeightFromFloat(f float64) (Height, error)

NewHeightFromFloat 创建一个新的 Height 实例,接受一个浮点数(单位:厘米)

func NewHeightFromTenths

func NewHeightFromTenths(t int64) Height

NewHeightFromTenths 从以 0.1 为单位的整数创建 Height 实例

func (Height) Float

func (h Height) Float() float64

Float 返回以厘米为单位的浮点数表示

func (Height) MarshalJSON

func (h Height) MarshalJSON() ([]byte, error)

JSON 序列化,输出 number(例如 170.5)

func (*Height) Scan

func (h *Height) Scan(src any) error

Scan 从数据库读取值

func (Height) String

func (h Height) String() string

Centimeters 返回以厘米为单位的整数表示

func (Height) Tenths

func (h Height) Tenths() int64

Centimeters 返回以厘米为单位的整数表示

func (*Height) UnmarshalJSON

func (h *Height) UnmarshalJSON(b []byte) error

JSON 反序列化,接受 number(例如 170.5)

func (Height) Value

func (h Height) Value() (driver.Value, error)

Value 转换为数据库值

type ID

type ID int64

ID:用 int64 映射数据库 BIGINT,天然规避 > MaxInt64 的问题

func FromInt64

func FromInt64(v int64) (ID, error)

FromInt64 从 int64 解析,负数报错

func FromUint64

func FromUint64(v uint64) ID

FromUint64 内部可信数据来源(若越界就 panic —— 逻辑错误尽早暴露)

func MustFromUint64

func MustFromUint64(v uint64) ID

MustFromUint64 显式 Must 版本(更清晰)

func New

func New() ID

New 内部生成(放你的雪花/序列器),保证 <= MaxInt64

func ParseID

func ParseID(s string) (ID, error)

ParseID 解析字符串形式的 ID

func (ID) Int64

func (id ID) Int64() int64

func (ID) IsZero

func (id ID) IsZero() bool

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口

func (*ID) Scan

func (id *ID) Scan(src any) error

Scan 实现 sql.Scanner 接口

func (ID) String

func (id ID) String() string

func (ID) Uint64

func (id ID) Uint64() uint64

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口

func (ID) Value

func (id ID) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口

type IDCard

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

IDCard 身份证值对象

func NewIDCard

func NewIDCard(name, number string) (IDCard, error)

NewIDCard 创建身份证值对象

func (IDCard) Equal

func (c IDCard) Equal(o IDCard) bool

func (IDCard) ID

func (c IDCard) ID() IDNumber

func (IDCard) Name

func (c IDCard) Name() string

func (IDCard) Number

func (c IDCard) Number() string

func (*IDCard) Scan

func (c *IDCard) Scan(src any) error

Scan 实现 database/sql.Scanner 接口,用于数据库读取

func (IDCard) String

func (c IDCard) String() string

func (IDCard) Value

func (c IDCard) Value() (driver.Value, error)

Value 实现 database/sql/driver.Valuer 接口,用于数据库写入

type IDNumber

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

func NewIDNumber

func NewIDNumber(raw string) (IDNumber, error)

NewIDNumber 解析/校验/归一化(支持 15 位旧号,自动转成 18 位)

func (IDNumber) BirthDate

func (id IDNumber) BirthDate() (time.Time, error)

BirthDate 解析出生日期

func (IDNumber) Equal

func (id IDNumber) Equal(o IDNumber) bool

func (IDNumber) IsEmpty

func (id IDNumber) IsEmpty() bool

func (IDNumber) IsMale

func (id IDNumber) IsMale() (bool, error)

IsMale 性别:奇数为男,偶数为女

func (IDNumber) MarshalJSON

func (id IDNumber) MarshalJSON() ([]byte, error)

func (IDNumber) Number

func (id IDNumber) Number() string

func (IDNumber) ProvinceCode

func (id IDNumber) ProvinceCode() string

ProvinceCode 省级代码(前两位)

func (*IDNumber) Scan

func (id *IDNumber) Scan(src any) error

func (IDNumber) String

func (id IDNumber) String() string

func (*IDNumber) UnmarshalJSON

func (id *IDNumber) UnmarshalJSON(b []byte) error

func (IDNumber) Value

func (id IDNumber) Value() (driver.Value, error)

type Phone

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

Phone 电话号码值对象

func NewPhone

func NewPhone(raw string) (Phone, error)

NewPhone 解析并创建 Phone 实例

func (Phone) Equal

func (p Phone) Equal(o Phone) bool

func (Phone) IsEmpty

func (p Phone) IsEmpty() bool

func (Phone) MarshalJSON

func (p Phone) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口,返回 JSON 编码值

func (Phone) Number

func (p Phone) Number() string

func (Phone) Region

func (p Phone) Region() (string, error)

(可选)拿地区;惰性解析

func (*Phone) Scan

func (p *Phone) Scan(src any) error

Scan 实现 sql.Scanner 接口,从数据库读取值

func (Phone) String

func (p Phone) String() string

func (*Phone) UnmarshalJSON

func (p *Phone) UnmarshalJSON(b []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口,解析 JSON 编码值

func (Phone) Value

func (p Phone) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,返回数据库存储值

type Weight

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

Weight 表示以 0.1 单位存储的体重(单位:千克,例如 70.5kg -> 705)

func NewWeightFromFloat

func NewWeightFromFloat(f float64) (Weight, error)

NewWeightFromFloat 创建一个新的 Weight 实例,接受一个浮点数(单位:千克)

func NewWeightFromTenths

func NewWeightFromTenths(t int64) Weight

NewWeightFromTenths 从以 0.1 为单位的整数创建 Weight 实例

func (Weight) Float

func (w Weight) Float() float64

Float 返回以千克为单位的浮点数表示

func (Weight) MarshalJSON

func (w Weight) MarshalJSON() ([]byte, error)

JSON 序列化,输出 number(例如 170.5)

func (*Weight) Scan

func (w *Weight) Scan(src any) error

Scan 从数据库读取值

func (Weight) String

func (w Weight) String() string

Centimeters 返回以千克为单位的整数表示

func (Weight) Tenths

func (w Weight) Tenths() int64

Centimeters 返回以千克为单位的整数表示

func (*Weight) UnmarshalJSON

func (w *Weight) UnmarshalJSON(b []byte) error

JSON 反序列化,接受 number(例如 170.5)

func (Weight) Value

func (w Weight) Value() (driver.Value, error)

Value 转换为数据库值

Jump to

Keyboard shortcuts

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