docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// 研究库文本 codec 适配:数据库用 SOH 转义 NUL,API 返回前还原原始文本。
|
||||
package research
|
||||
|
||||
import (
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
// SOH -> SOH/STX. All other bytes retain their original binary ordering.
|
||||
const textCodec = "nul-soh-v1"
|
||||
|
||||
// encodedSchema 仅识别精确协议版本;无标注视为普通文本,未知版本阻止启动,避免错误解码。
|
||||
func encodedSchema(annotation sql.NullString) (bool, error) {
|
||||
const prefix = "paper-atlas:text-codec="
|
||||
if !annotation.Valid || !strings.HasPrefix(annotation.String, prefix) {
|
||||
@@ -21,10 +23,12 @@ func encodedSchema(annotation sql.NullString) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// encodeText 必须先转义 SOH 再转义 NUL,防止第二次替换改写刚生成的转义序列。
|
||||
func encodeText(value string) string {
|
||||
return strings.ReplaceAll(strings.ReplaceAll(value, "\x01", "\x01\x02"), "\x00", "\x01\x01")
|
||||
}
|
||||
|
||||
// decodeText 逐段复制普通字节,仅接受 SOH/SOH 与 SOH/STX;残缺或未知转义立即报错。
|
||||
func decodeText(value string) (string, error) {
|
||||
if !strings.ContainsRune(value, '\x01') {
|
||||
return value, nil
|
||||
@@ -52,11 +56,13 @@ func decodeText(value string) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// textColumn 实现 sql.Scanner,把可选 codec 与目标字段的 NULL 语义集中处理。
|
||||
type textColumn struct {
|
||||
encoded bool
|
||||
target any
|
||||
}
|
||||
|
||||
// Scan 先用 NullString 接收驱动值,再按 schema 解码;非空字符串目标不允许数据库 NULL。
|
||||
func (column textColumn) Scan(source any) error {
|
||||
var value sql.NullString
|
||||
if err := value.Scan(source); err != nil {
|
||||
@@ -83,6 +89,7 @@ func (column textColumn) Scan(source any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// text 在 scanPaper/enrich 中包装文本列,避免遗漏对来源元数据或主题的解码。
|
||||
func (r *PostgresRepository) text(target any) sql.Scanner {
|
||||
return textColumn{encoded: r.encoded, target: target}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user