feat(encoding): 具名化 JS 导出并动态包裹错误(by AI)
This commit is contained in:
parent
d1ff9159e4
commit
b05c586efb
@ -1,5 +1,10 @@
|
||||
# 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。
|
||||
|
||||
|
||||
4
go.mod
4
go.mod
@ -2,6 +2,6 @@ module apigo.cc/go/encoding
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require apigo.cc/go/cast v1.5.2
|
||||
require apigo.cc/go/cast v1.5.3
|
||||
|
||||
require apigo.cc/go/jsmod v1.5.2
|
||||
require apigo.cc/go/jsmod v1.5.3
|
||||
|
||||
76
js_export.go
76
js_export.go
@ -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))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user