refactor: 将客服后端重构为宿主可嵌入模块
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func TestRequestStructTagsUseSnakeCase(t *testing.T) {
|
||||
fset := token.NewFileSet()
|
||||
packages, err := parser.ParseDir(fset, ".", nil, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("parse request package: %v", err)
|
||||
}
|
||||
|
||||
for _, pkg := range packages {
|
||||
for filename, file := range pkg.Files {
|
||||
ast.Inspect(file, func(node ast.Node) bool {
|
||||
field, ok := node.(*ast.Field)
|
||||
if !ok || field.Tag == nil {
|
||||
return true
|
||||
}
|
||||
rawTag, err := strconv.Unquote(field.Tag.Value)
|
||||
if err != nil {
|
||||
t.Errorf("%s: invalid struct tag %s: %v", filename, field.Tag.Value, err)
|
||||
return true
|
||||
}
|
||||
for _, key := range []string{"json", "form", "query", "uri"} {
|
||||
name := strings.Split(reflect.StructTag(rawTag).Get(key), ",")[0]
|
||||
if name == "" || name == "-" {
|
||||
continue
|
||||
}
|
||||
if !isSnakeCaseRequestName(name) {
|
||||
t.Errorf("%s: %s tag %q must use snake_case", filename, key, name)
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isSnakeCaseRequestName(name string) bool {
|
||||
for _, r := range name {
|
||||
if unicode.IsLower(r) || unicode.IsDigit(r) || r == '_' {
|
||||
continue
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user