feat: 引入依赖注入模式
- 创建Repository接口定义(UserRepository、ProfileRepository、TextureRepository等) - 创建Repository接口实现 - 创建依赖注入容器(container.Container) - 改造Handler层使用依赖注入(AuthHandler、UserHandler、TextureHandler) - 创建新的路由注册方式(RegisterRoutesWithDI) - 提供main.go示例文件展示如何使用依赖注入 同时包含之前的安全修复: - CORS配置安全加固 - 头像URL验证安全修复 - JWT algorithm confusion漏洞修复 - Recovery中间件增强 - 敏感错误信息泄露修复 - 类型断言安全修复
This commit is contained in:
@@ -160,8 +160,8 @@ func SearchTextures(c *gin.Context) {
|
||||
textureTypeStr := c.Query("type")
|
||||
publicOnly := c.Query("public_only") == "true"
|
||||
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
||||
page := parseIntWithDefault(c.DefaultQuery("page", "1"), 1)
|
||||
pageSize := parseIntWithDefault(c.DefaultQuery("page_size", "20"), 20)
|
||||
|
||||
var textureType model.TextureType
|
||||
switch textureTypeStr {
|
||||
@@ -314,8 +314,8 @@ func GetUserTextures(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
||||
page := parseIntWithDefault(c.DefaultQuery("page", "1"), 1)
|
||||
pageSize := parseIntWithDefault(c.DefaultQuery("page_size", "20"), 20)
|
||||
|
||||
textures, total, err := service.GetUserTextures(database.MustGetDB(), userID, page, pageSize)
|
||||
if err != nil {
|
||||
@@ -344,8 +344,8 @@ func GetUserFavorites(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
||||
page := parseIntWithDefault(c.DefaultQuery("page", "1"), 1)
|
||||
pageSize := parseIntWithDefault(c.DefaultQuery("page_size", "20"), 20)
|
||||
|
||||
textures, total, err := service.GetUserTextureFavorites(database.MustGetDB(), userID, page, pageSize)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user