lcore

module
v2.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0

README

lcore

test codecov

中文 | English

面向 PostgreSQL + GORM 的 Go 值类型:本地时间、UUID、decimal、数组列表。

多数类型实现 json.Marshalerdriver.Valuersql.Scanner,便于 API 与数据库互通。

功能特性

  • 本地时间LocalDateLocalTimeLocalDateTime:墙上时钟语义(等同 Java LocalDate 等),统一 time.Local
  • 标量UUID(JSON:无连字符 32 位 hex;数据库:标准 UUID 字符串);shopspring/decimal 辅助;NullUint64
  • PG 数组 List
    • 文本 / 布尔:StringListBoolList
    • 整型:IntListInt16ListInt32ListInt64List
    • 浮点 / decimal:Float64ListDecimalList
    • UUID / 日期时间:UUIDListLocalDateListLocalTimeListLocalDateTimeList
  • 混合数组Array:仅写出(Value);暂无 Scan
  • 工具NewInt / NewString / NewBoolNilToZeroFields

安装

# 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

Directories

Path Synopsis
Package types 提供 PostgreSQL/GORM 场景下的本地时间、数组列表、UUID、decimal 等值类型与工具函数。
Package types 提供 PostgreSQL/GORM 场景下的本地时间、数组列表、UUID、decimal 等值类型与工具函数。

Jump to

Keyboard shortcuts

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