From aa2229d6b382d68392aedc136ee8f408e19b75b4 Mon Sep 17 00:00:00 2001 From: AI Engineer Date: Mon, 8 Jun 2026 22:20:48 +0800 Subject: [PATCH] feat: simplify JS exports to a single Make method (by AI) --- CHANGELOG.md | 3 +++ js_export.go | 26 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbeb678..e020fbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog: @go/id +## v1.5.1 (2026-06-08) +- **JS 极简 API**: 彻底废除 JS 侧冗长难记的 `get8Bytes...` 等方法,统一收敛为极简的 `Make(size int, forDB ...string)`。充分利用了底层 JS Bridge 的零值回退特性,在不填第二个参数时也能安全优雅地工作。 + ## [v1.3.2] - 2026-05-30 ### Added diff --git a/js_export.go b/js_export.go index 8c9b4ac..a96b28a 100644 --- a/js_export.go +++ b/js_export.go @@ -1,13 +1,27 @@ package id -import "apigo.cc/go/jsmod" +import ( + "strings" + + "apigo.cc/go/jsmod" +) func init() { jsmod.Register("id", map[string]any{ - "get8Bytes4KPerSecond": Get8Bytes4KPerSecond, - "get9Bytes90KPerSecond": Get9Bytes90KPerSecond, - "get10Bytes14MPerSecond": Get10Bytes14MPerSecond, - "get11Bytes900MPerSecond": Get11Bytes900MPerSecond, - "get12BytesUltraPerSecond": Get12BytesUltraPerSecond, + "Make": func(size int, forDB ...string) string { + dbType := "" + if len(forDB) > 0 { + dbType = strings.ToLower(forDB[0]) + } + + switch dbType { + case "mysql": + return DefaultIDMaker.GetForMysql(size) + case "postgres", "pg", "pgsql": + return DefaultIDMaker.GetForPostgreSQL(size) + default: + return DefaultIDMaker.Get(size) + } + }, }) }