refactor(main): 重构主应用结构以提高模块化
- 将main.go中的初始化逻辑提取到新的app包中 - 创建bootstrap包来处理配置加载和数据库初始化 - 添加middleware包来管理CORS中间件 - 创建router包来处理路由配置 - 简化main函数,只保留应用启动逻辑 - 使用依赖注入模式组织服务和处理器
This commit is contained in:
25
memora-api/internal/router/router.go
Normal file
25
memora-api/internal/router/router.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"memora-api/internal/handler"
|
||||
"memora-api/internal/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func New(wordHandler *handler.WordHandler) *gin.Engine {
|
||||
r := gin.Default()
|
||||
r.Use(middleware.CORS())
|
||||
|
||||
api := r.Group("/api")
|
||||
{
|
||||
api.POST("/words", wordHandler.AddWord)
|
||||
api.GET("/words", wordHandler.GetWords)
|
||||
api.GET("/review", wordHandler.GetReviewWords)
|
||||
api.POST("/review", wordHandler.SubmitReview)
|
||||
api.GET("/stats", wordHandler.GetStatistics)
|
||||
api.GET("/audio", wordHandler.GetAudio)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user