Compare commits

...

2 Commits

Author SHA1 Message Date
AI Engineer
b05c586efb feat(encoding): 具名化 JS 导出并动态包裹错误(by AI) 2026-06-21 10:11:57 +08:00
AI Engineer
d1ff9159e4 chore: align dependencies to v1.5.2 (by AI) 2026-06-11 19:12:37 +08:00
3 changed files with 65 additions and 23 deletions

View File

@ -1,5 +1,13 @@
# Changelog: @go/encoding
## v1.5.4 (2026-06-21)
- **重构与错误堆栈支持**:
- 重构 `js_export.go`,将 `EncodeInt` 等匿名包装以及 `UnHex`/`UnBase64`/`UnURLBase64`/`UnURLEncode` 直接抛错的 Go 接口重写为具名函数,并动态使用 `jsmod.MakeError` 包裹错误。
- 升级 `jsmod` 依赖至 v1.5.3`cast` 依赖至 v1.5.3。
## v1.5.3 (2026-06-11)
- **依赖对齐**: 升级 `jsmod` 依赖至 v1.5.2,升级 `cast` 依赖至 v1.5.2。
## v1.5.2 (2026-06-08)
- **回滚与修复**: 修正了 `v1.5.1` 中架构设计的失误,将 Go 核心层的 `EncodeInt``IntEncoder.EncodeInt` 返回值从 `string` 恢复为 `[]byte`,彻底消除由于频繁强制转换导致的内存逃逸,恢复了高频并发场景下的零拷贝性能基准。
- **JS 智能桥接**: 通过在 `js_export.go` 的注册阶段采用匿名闭包函数 `func(u uint64) string`,完美兼顾了底层的高效性和 JS 环境面向字符串开发的友好体验。

4
go.mod
View File

@ -2,6 +2,6 @@ module apigo.cc/go/encoding
go 1.25.0
require apigo.cc/go/cast v1.5.0
require apigo.cc/go/cast v1.5.3
require apigo.cc/go/jsmod v1.5.0
require apigo.cc/go/jsmod v1.5.3

View File

@ -4,26 +4,60 @@ import "apigo.cc/go/jsmod"
func init() {
jsmod.Register("encoding", map[string]any{
"Base64": Base64,
"Base64Raw": Base64Raw,
"UnBase64": UnBase64,
"URLBase64": URLBase64,
"URLBase64Raw": URLBase64Raw,
"UnURLBase64": UnURLBase64,
"Hex": Hex,
"UnHex": UnHex,
"URLEncode": URLEncode,
"UnURLEncode": UnURLEncode,
"HTMLEscape": HTMLEscape,
"HTMLUnescape": HTMLUnescape,
"UTF8Valid": UTF8Valid,
"SortJoin": SortJoin,
"EncodeInt": func(u uint64) string {
return string(EncodeInt(u))
},
"DecodeInt": DecodeInt,
"FillInt": FillInt,
"ExchangeInt": ExchangeInt,
"HashInt": HashInt,
"Base64": Base64,
"Base64Raw": Base64Raw,
"UnBase64": jsUnBase64,
"URLBase64": URLBase64,
"URLBase64Raw": URLBase64Raw,
"UnURLBase64": jsUnURLBase64,
"Hex": Hex,
"UnHex": jsUnHex,
"URLEncode": URLEncode,
"UnURLEncode": jsUnURLEncode,
"HTMLEscape": HTMLEscape,
"HTMLUnescape": HTMLUnescape,
"UTF8Valid": UTF8Valid,
"SortJoin": SortJoin,
"EncodeInt": jsEncodeInt,
"DecodeInt": DecodeInt,
"FillInt": FillInt,
"ExchangeInt": ExchangeInt,
"HashInt": HashInt,
})
}
func jsUnBase64(data any) ([]byte, error) {
res, err := UnBase64(data)
if err != nil {
return nil, jsmod.MakeError(err)
}
return res, nil
}
func jsUnURLBase64(data any) ([]byte, error) {
res, err := UnURLBase64(data)
if err != nil {
return nil, jsmod.MakeError(err)
}
return res, nil
}
func jsUnHex(data any) ([]byte, error) {
res, err := UnHex(data)
if err != nil {
return nil, jsmod.MakeError(err)
}
return res, nil
}
func jsUnURLEncode(data any) ([]byte, error) {
res, err := UnURLEncode(data)
if err != nil {
return nil, jsmod.MakeError(err)
}
return res, nil
}
func jsEncodeInt(u uint64) string {
return string(EncodeInt(u))
}