fix: golangci-lint 零告警通过 (57→0) + gofumpt/goimports 全量格式化
## CI 修复 (P0/P1) P0 — 编译阻塞: - interfaces.go: postUseCase ISP 接口移除不用的 Create/Update/Delete P1 — 必须修复: - ST1000: 为 13 个包添加包注释 (common/config/model/service/...) - ST1005: redis_store.go 全部错误消息改为小写开头 - errcheck (19处): defer Close()→闭包忽略, notifier.Create→_=, r.Run→检查error - errorlint (9处): switch-on-error→errors.Is 链, ==→errors.Is - ST1020/ST1022: 导出符号注释以符号名开头 P2 — 安全评审: - gosec (12处): G203/G301/G304/G306 添加 nolint 注释并附理由 P3 — 清理: - unused: 移除 hasUnicode/energyStore/current/energyAdminUseCase - gofumpt + goimports 全量格式化 (35+ 文件)
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@ -39,18 +40,17 @@ func (ec *EnergyController) Energize(c *gin.Context) {
|
||||
|
||||
expGained, actualAmount, err := ec.energySvc.Energize(uid, req.PostID, req.Amount)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case common.ErrPostNotFound:
|
||||
if errors.Is(err, common.ErrPostNotFound) {
|
||||
common.Error(c, http.StatusNotFound, "文章不存在")
|
||||
case common.ErrCannotEnergizeSelf:
|
||||
} else if errors.Is(err, common.ErrCannotEnergizeSelf) {
|
||||
common.Error(c, http.StatusBadRequest, "不能给自己的文章赋能")
|
||||
case common.ErrInsufficientEnergy:
|
||||
} else if errors.Is(err, common.ErrInsufficientEnergy) {
|
||||
common.Error(c, http.StatusBadRequest, "域能不足,可通过每日签到或创作被赋能获取")
|
||||
case common.ErrEnergizeLimitReached:
|
||||
} else if errors.Is(err, common.ErrEnergizeLimitReached) {
|
||||
common.Error(c, http.StatusBadRequest, "对该文章赋能已达上限")
|
||||
case common.ErrInvalidEnergyAmount:
|
||||
} else if errors.Is(err, common.ErrInvalidEnergyAmount) {
|
||||
common.Error(c, http.StatusBadRequest, "无效的赋能数量")
|
||||
default:
|
||||
} else {
|
||||
common.Error(c, http.StatusInternalServerError, "赋能失败")
|
||||
}
|
||||
return
|
||||
@ -136,13 +136,13 @@ func (ec *EnergyController) GetEnergyLogs(c *gin.Context) {
|
||||
|
||||
// EnergyLogView 前端展示用的域能流水视图
|
||||
type EnergyLogView struct {
|
||||
ID uint `json:"id"`
|
||||
Amount int `json:"amount"`
|
||||
ID uint `json:"id"`
|
||||
Amount int `json:"amount"`
|
||||
AmountDisplay float64 `json:"amount_display"`
|
||||
Type string `json:"type"`
|
||||
TypeName string `json:"type_name"`
|
||||
Description string `json:"description"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Type string `json:"type"`
|
||||
TypeName string `json:"type_name"`
|
||||
Description string `json:"description"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
func toEnergyLogViews(logs []model.EnergyLog) []EnergyLogView {
|
||||
|
||||
Reference in New Issue
Block a user