refactor: 重构代码架构并使用 Modern Go 特性
- 重命名模块 jwts -> schedule_converter
- 新增 service 包,统一业务逻辑层
- 新增 pkg/logger 包,使用 slog 结构化日志
- 新增 pkg/errors 包,统一错误处理
- 拆分 captcha 包,图片识别移至 service/recognizer
- 清理 models 包,只保留数据结构定义
- 消除 grpc/handler.go 中的重复代码
- 简化 main.go,使用 slog 和 context
- 配置支持单例模式和结构化配置
- 使用 any 替代 interface{}
- 使用 sync.Map 替代 map + RWMutex
This commit is contained in:
@@ -11,8 +11,8 @@ type APIRequest struct {
|
||||
|
||||
// Message 消息结构
|
||||
type Message struct {
|
||||
Role string `json:"role"`
|
||||
Content interface{} `json:"content"`
|
||||
Role string `json:"role"`
|
||||
Content any `json:"content"`
|
||||
}
|
||||
|
||||
// ContentItem 内容项
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func SaveToJSON(courses []Course, filename string) error {
|
||||
jsonData, err := json.MarshalIndent(courses, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.WriteFile(filename, jsonData, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("[输出] JSON结果已保存到: %s\n", filename)
|
||||
return nil
|
||||
}
|
||||
|
||||
func PrintCourses(courses []Course) {
|
||||
fmt.Println("\n==================================================")
|
||||
fmt.Println("识别结果:")
|
||||
fmt.Println("==================================================")
|
||||
for i, course := range courses {
|
||||
fmt.Printf("\n课程 %d: %s\n", i+1, course.Name)
|
||||
fmt.Printf(" 教师: %s\n", course.Teacher)
|
||||
fmt.Printf(" 教室: %s\n", course.Room)
|
||||
fmt.Printf(" 时间:")
|
||||
for _, sch := range course.Schedule {
|
||||
fmt.Printf(" %s %v 周%v", sch.Day, sch.Section, sch.Weeks)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
fmt.Println("\n==================================================")
|
||||
}
|
||||
Reference in New Issue
Block a user