mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-02 14:53:55 +08:00
refactor: update struct field types from interface{} to any for improved type safety
This commit is contained in:
@@ -24,47 +24,47 @@ type CodeSnippetRepo interface {
|
||||
|
||||
// 请求结构体
|
||||
type CreateCodeSnippetReq struct {
|
||||
WorkspaceFileID string `json:"workspace_file_id" validate:"required"` // 关联的workspace file ID
|
||||
Name string `json:"name"` // 代码片段名称
|
||||
SnippetType string `json:"snippet_type"` // 代码片段类型 (function, class, variable, etc.)
|
||||
Language string `json:"language"` // 编程语言
|
||||
Content string `json:"content"` // 代码片段内容
|
||||
Hash string `json:"hash"` // 内容哈希
|
||||
StartLine int `json:"start_line"` // 起始行号
|
||||
EndLine int `json:"end_line"` // 结束行号
|
||||
StartColumn int `json:"start_column"` // 起始列号
|
||||
EndColumn int `json:"end_column"` // 结束列号
|
||||
Namespace string `json:"namespace"` // 命名空间
|
||||
ContainerName string `json:"container_name"` // 容器名称 (类名、模块名等)
|
||||
Scope []string `json:"scope"` // 作用域信息
|
||||
Dependencies []string `json:"dependencies"` // 依赖项
|
||||
Parameters []map[string]interface{} `json:"parameters"` // 参数列表
|
||||
Signature string `json:"signature"` // 函数签名
|
||||
DefinitionText string `json:"definition_text"` // 定义文本
|
||||
StructuredInfo map[string]interface{} `json:"structured_info"` // 结构化信息
|
||||
WorkspaceFileID string `json:"workspace_file_id" validate:"required"` // 关联的workspace file ID
|
||||
Name string `json:"name"` // 代码片段名称
|
||||
SnippetType string `json:"snippet_type"` // 代码片段类型 (function, class, variable, etc.)
|
||||
Language string `json:"language"` // 编程语言
|
||||
Content string `json:"content"` // 代码片段内容
|
||||
Hash string `json:"hash"` // 内容哈希
|
||||
StartLine int `json:"start_line"` // 起始行号
|
||||
EndLine int `json:"end_line"` // 结束行号
|
||||
StartColumn int `json:"start_column"` // 起始列号
|
||||
EndColumn int `json:"end_column"` // 结束列号
|
||||
Namespace string `json:"namespace"` // 命名空间
|
||||
ContainerName string `json:"container_name"` // 容器名称 (类名、模块名等)
|
||||
Scope []string `json:"scope"` // 作用域信息
|
||||
Dependencies []string `json:"dependencies"` // 依赖项
|
||||
Parameters []map[string]any `json:"parameters"` // 参数列表
|
||||
Signature string `json:"signature"` // 函数签名
|
||||
DefinitionText string `json:"definition_text"` // 定义文本
|
||||
StructuredInfo map[string]any `json:"structured_info"` // 结构化信息
|
||||
}
|
||||
|
||||
// 数据模型
|
||||
type CodeSnippet struct {
|
||||
ID string `json:"id"` // 代码片段ID
|
||||
WorkspaceFileID string `json:"workspace_file_id"` // 关联的workspace file ID
|
||||
Name string `json:"name"` // 代码片段名称
|
||||
SnippetType string `json:"snippet_type"` // 代码片段类型
|
||||
Language string `json:"language"` // 编程语言
|
||||
Content string `json:"content"` // 代码片段内容
|
||||
Hash string `json:"hash"` // 内容哈希
|
||||
StartLine int `json:"start_line"` // 起始行号
|
||||
EndLine int `json:"end_line"` // 结束行号
|
||||
StartColumn int `json:"start_column"` // 起始列号
|
||||
EndColumn int `json:"end_column"` // 结束列号
|
||||
Namespace string `json:"namespace"` // 命名空间
|
||||
ContainerName string `json:"container_name"` // 容器名称
|
||||
Scope []string `json:"scope"` // 作用域信息
|
||||
Dependencies []string `json:"dependencies"` // 依赖项
|
||||
Parameters []map[string]interface{} `json:"parameters"` // 参数列表
|
||||
Signature string `json:"signature"` // 函数签名
|
||||
DefinitionText string `json:"definition_text"` // 定义文本
|
||||
StructuredInfo map[string]interface{} `json:"structured_info"` // 结构化信息
|
||||
ID string `json:"id"` // 代码片段ID
|
||||
WorkspaceFileID string `json:"workspace_file_id"` // 关联的workspace file ID
|
||||
Name string `json:"name"` // 代码片段名称
|
||||
SnippetType string `json:"snippet_type"` // 代码片段类型
|
||||
Language string `json:"language"` // 编程语言
|
||||
Content string `json:"content"` // 代码片段内容
|
||||
Hash string `json:"hash"` // 内容哈希
|
||||
StartLine int `json:"start_line"` // 起始行号
|
||||
EndLine int `json:"end_line"` // 结束行号
|
||||
StartColumn int `json:"start_column"` // 起始列号
|
||||
EndColumn int `json:"end_column"` // 结束列号
|
||||
Namespace string `json:"namespace"` // 命名空间
|
||||
ContainerName string `json:"container_name"` // 容器名称
|
||||
Scope []string `json:"scope"` // 作用域信息
|
||||
Dependencies []string `json:"dependencies"` // 依赖项
|
||||
Parameters []map[string]any `json:"parameters"` // 参数列表
|
||||
Signature string `json:"signature"` // 函数签名
|
||||
DefinitionText string `json:"definition_text"` // 定义文本
|
||||
StructuredInfo map[string]any `json:"structured_info"` // 结构化信息
|
||||
}
|
||||
|
||||
func (c *CodeSnippet) From(e *db.CodeSnippet) *CodeSnippet {
|
||||
|
||||
@@ -60,18 +60,18 @@ type WorkspaceFileRepo interface {
|
||||
// 请求结构体
|
||||
|
||||
type CreateWorkspaceReq struct {
|
||||
UserID string `json:"user_id" validate:"required"` // 用户ID
|
||||
Name string `json:"name" validate:"required"` // 工作区名称
|
||||
Description string `json:"description"` // 工作区描述
|
||||
RootPath string `json:"root_path" validate:"required"` // 工作区根路径
|
||||
Settings map[string]interface{} `json:"settings"` // 工作区设置
|
||||
UserID string `json:"user_id" validate:"required"` // 用户ID
|
||||
Name string `json:"name" validate:"required"` // 工作区名称
|
||||
Description string `json:"description"` // 工作区描述
|
||||
RootPath string `json:"root_path" validate:"required"` // 工作区根路径
|
||||
Settings map[string]any `json:"settings"` // 工作区设置
|
||||
}
|
||||
|
||||
type UpdateWorkspaceReq struct {
|
||||
ID string `json:"id" validate:"required"` // 工作区ID
|
||||
Name *string `json:"name"` // 工作区名称
|
||||
Description *string `json:"description"` // 工作区描述
|
||||
Settings map[string]interface{} `json:"settings"` // 工作区设置
|
||||
ID string `json:"id" validate:"required"` // 工作区ID
|
||||
Name *string `json:"name"` // 工作区名称
|
||||
Description *string `json:"description"` // 工作区描述
|
||||
Settings map[string]any `json:"settings"` // 工作区设置
|
||||
}
|
||||
|
||||
type ListWorkspaceReq struct {
|
||||
@@ -151,15 +151,15 @@ type SyncWorkspaceFileResp struct {
|
||||
// 数据模型
|
||||
|
||||
type Workspace struct {
|
||||
ID string `json:"id"` // 工作区ID
|
||||
UserID string `json:"user_id"` // 用户ID
|
||||
Name string `json:"name"` // 工作区名称
|
||||
Description string `json:"description"` // 工作区描述
|
||||
RootPath string `json:"root_path"` // 工作区根路径
|
||||
Settings map[string]interface{} `json:"settings"` // 工作区设置
|
||||
LastAccessedAt int64 `json:"last_accessed_at"` // 最后访问时间
|
||||
CreatedAt int64 `json:"created_at"` // 创建时间
|
||||
UpdatedAt int64 `json:"updated_at"` // 更新时间
|
||||
ID string `json:"id"` // 工作区ID
|
||||
UserID string `json:"user_id"` // 用户ID
|
||||
Name string `json:"name"` // 工作区名称
|
||||
Description string `json:"description"` // 工作区描述
|
||||
RootPath string `json:"root_path"` // 工作区根路径
|
||||
Settings map[string]any `json:"settings"` // 工作区设置
|
||||
LastAccessedAt int64 `json:"last_accessed_at"` // 最后访问时间
|
||||
CreatedAt int64 `json:"created_at"` // 创建时间
|
||||
UpdatedAt int64 `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
type WorkspaceFile struct {
|
||||
|
||||
@@ -33,7 +33,7 @@ func (Workspace) Fields() []ent.Field {
|
||||
field.String("name").Optional().Comment("工作区名称"),
|
||||
field.String("description").Optional().Comment("工作区描述"),
|
||||
field.String("root_path").NotEmpty().Comment("工作区根路径"),
|
||||
field.JSON("settings", map[string]interface{}{}).Optional().Comment("工作区设置"),
|
||||
field.JSON("settings", map[string]any{}).Optional().Comment("工作区设置"),
|
||||
field.Time("last_accessed_at").Default(time.Now).Comment("最后访问时间"),
|
||||
field.Time("created_at").Default(time.Now).Immutable().Comment("创建时间"),
|
||||
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now).Comment("更新时间"),
|
||||
|
||||
@@ -38,13 +38,13 @@ func (u *CodeSnippetUsecase) CreateFromIndexResult(ctx context.Context, workspac
|
||||
// StartColumn 和 EndColumn 在 IndexResult 中没有直接对应字段,暂时设置为 0
|
||||
StartColumn: 0,
|
||||
EndColumn: 0,
|
||||
Namespace: "", // IndexResult 中没有直接对应字段
|
||||
ContainerName: "", // IndexResult 中没有直接对应字段
|
||||
Dependencies: []string{}, // IndexResult 中没有直接对应字段
|
||||
Parameters: []map[string]interface{}{}, // IndexResult 中没有直接对应字段
|
||||
Namespace: "", // IndexResult 中没有直接对应字段
|
||||
ContainerName: "", // IndexResult 中没有直接对应字段
|
||||
Dependencies: []string{}, // IndexResult 中没有直接对应字段
|
||||
Parameters: []map[string]any{}, // IndexResult 中没有直接对应字段
|
||||
Signature: indexResult.Signature,
|
||||
DefinitionText: indexResult.DefinitionText,
|
||||
StructuredInfo: map[string]interface{}{
|
||||
StructuredInfo: map[string]any{
|
||||
"definition": indexResult.Definition,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -350,10 +350,10 @@ func (h *SocketHandler) processFileUpdateAsync(socket *socketio.Socket, updateDa
|
||||
codeFiles := domain.CodeFiles{
|
||||
Files: []domain.FileMeta{
|
||||
{
|
||||
FilePath: updateData.FilePath,
|
||||
FileExtension: fileExtension,
|
||||
Language: h.getFileLanguage(fileExtension),
|
||||
Content: updateData.Content,
|
||||
FilePath: updateData.FilePath,
|
||||
// FileExtension: fileExtension,
|
||||
Language: h.getFileLanguage(fileExtension),
|
||||
Content: updateData.Content,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -432,10 +432,10 @@ func (h *SocketHandler) processFileUpdateAsync(socket *socketio.Socket, updateDa
|
||||
codeFiles := domain.CodeFiles{
|
||||
Files: []domain.FileMeta{
|
||||
{
|
||||
FilePath: updateData.FilePath,
|
||||
FileExtension: fileExtension,
|
||||
Language: h.getFileLanguage(fileExtension),
|
||||
Content: updateData.Content,
|
||||
FilePath: updateData.FilePath,
|
||||
// FileExtension: fileExtension,
|
||||
Language: h.getFileLanguage(fileExtension),
|
||||
Content: updateData.Content,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (u *WorkspaceUsecase) EnsureWorkspace(ctx context.Context, userID, rootPath
|
||||
Name: name,
|
||||
Description: fmt.Sprintf("Auto-created workspace for %s", rootPath),
|
||||
RootPath: rootPath,
|
||||
Settings: map[string]interface{}{},
|
||||
Settings: map[string]any{},
|
||||
}
|
||||
|
||||
return u.Create(ctx, createReq)
|
||||
|
||||
Reference in New Issue
Block a user