lcore

中文 | English
面向 PostgreSQL + GORM 的 Go 值类型:本地时间、UUID、decimal、数组列表。
多数类型实现 json.Marshaler、driver.Valuer、sql.Scanner,便于 API 与数据库互通。
功能特性
- 本地时间 —
LocalDate、LocalTime、LocalDateTime:墙上时钟语义(等同 Java LocalDate 等),统一 time.Local
- 标量 —
UUID(JSON:无连字符 32 位 hex;数据库:标准 UUID 字符串);shopspring/decimal 辅助;NullUint64
- PG 数组 List
- 文本 / 布尔:
StringList、BoolList
- 整型:
IntList、Int16List、Int32List、Int64List
- 浮点 / decimal:
Float64List、DecimalList
- UUID / 日期时间:
UUIDList、LocalDateList、LocalTimeList、LocalDateTimeList
- 混合数组 —
Array:仅写出(Value);暂无 Scan
- 工具 —
NewInt / NewString / NewBool、NilToZero、Fields 等
安装
# v2(当前模块,推荐)
go get -u github.com/lontten/lcore/v2
# v1(历史版本)
go get -u github.com/lontten/lcore
import "github.com/lontten/lcore/v2/types"
快速上手
package main
import (
"encoding/json"
"fmt"
"github.com/lontten/lcore/v2/types"
)
func main() {
d := types.LocalDateOfYmd(2026, 6, 23)
b, _ := json.Marshal(d)
fmt.Println(string(b)) // "2026-06-23"
id := types.Str2UUIDMust("550e8400-e29b-41d4-a716-446655440000")
b, _ = json.Marshal(id)
fmt.Println(string(b)) // "550e8400e29b41d4a716446655440000"
}
下面是一个 GORM 模型示例:
type Product struct {
ID types.UUID `gorm:"type:uuid"`
Tags types.StringList `gorm:"type:text[]"`
Scores types.Int32List `gorm:"type:int4[]"`
Day types.LocalDate `gorm:"type:date"`
}
开发与测试
需要 Go 1.25+。本仓库为库模块,无 main 包。
go mod verify
go test -race -count=1 ./...
覆盖率由 CI 上传至 Codecov。
许可证
Apache 2.0 — 见 LICENSE。