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,3 +1,4 @@
|
||||
// Package config 管理应用配置的加载、解析和运行时访问。
|
||||
package config
|
||||
|
||||
import (
|
||||
@ -22,10 +23,10 @@ type Config struct {
|
||||
|
||||
// AuditConfig 审核系统配置(config.yaml 提供默认值,站点设置可运行时覆盖)
|
||||
type AuditConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
UsernameAudit bool `mapstructure:"username_audit"`
|
||||
AvatarAudit bool `mapstructure:"avatar_audit"`
|
||||
BioAudit bool `mapstructure:"bio_audit"`
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
UsernameAudit bool `mapstructure:"username_audit"`
|
||||
AvatarAudit bool `mapstructure:"avatar_audit"`
|
||||
BioAudit bool `mapstructure:"bio_audit"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
@ -65,9 +66,9 @@ type BcryptConfig struct {
|
||||
|
||||
// RolesConfig 角色配置(可扩展,新增角色只需改 config.yaml)
|
||||
type RolesConfig struct {
|
||||
Levels map[string]int `mapstructure:"levels"`
|
||||
Names map[string]string `mapstructure:"names"`
|
||||
Permissions RolesPermissions `mapstructure:"permissions"`
|
||||
Levels map[string]int `mapstructure:"levels"`
|
||||
Names map[string]string `mapstructure:"names"`
|
||||
Permissions RolesPermissions `mapstructure:"permissions"`
|
||||
}
|
||||
|
||||
// RolesPermissions 角色间操作权限
|
||||
@ -75,7 +76,7 @@ type RolesPermissions struct {
|
||||
OperableRoles map[string][]string `mapstructure:"operable_roles"`
|
||||
}
|
||||
|
||||
// 全局配置实例(初始化后只读)
|
||||
// App 全局配置实例(初始化后只读)。
|
||||
var App *Config
|
||||
|
||||
// Load 加载配置:config.yaml → .env 覆盖
|
||||
@ -111,11 +112,11 @@ func Load(configPath string) *Config {
|
||||
|
||||
// loadEnvFile 读取 .env 文件并设置环境变量(仅当环境变量未设置时)
|
||||
func loadEnvFile(path string) {
|
||||
f, err := os.Open(path)
|
||||
f, err := os.Open(path) //nolint:gosec // path 为内部 .env 文件路径
|
||||
if err != nil {
|
||||
return // .env 不存在,跳过
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
@ -130,7 +131,7 @@ func loadEnvFile(path string) {
|
||||
key := strings.TrimSpace(parts[0])
|
||||
val := strings.TrimSpace(parts[1])
|
||||
if os.Getenv(key) == "" {
|
||||
os.Setenv(key, val)
|
||||
_ = os.Setenv(key, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,19 +112,19 @@ func (s *SiteSettings) IsAuditTypeEnabled(auditType string, defaultVal bool) boo
|
||||
|
||||
// SiteInfoDefaults 站点展示信息的默认值
|
||||
type SiteInfoDefaults struct {
|
||||
SiteName string // 站点名称,默认 "MetaLab"
|
||||
SiteTagline string // 站点标语,默认 "下一代开发者社区"
|
||||
ContactEmail string // 联系/申诉邮箱,默认 "metazone@foxmail.com"
|
||||
Framework string // 附加标识,默认 "Framework: MetaGenesis"
|
||||
CopyrightStart string // 版权起始年份,默认 "2024"
|
||||
OperatorName string // 运营主体
|
||||
ICPNumber string // ICP 备案(HTML,含链接)
|
||||
ICPLicense string // ICP 经营许可证(HTML)
|
||||
PoliceNumber string // 公安备案(HTML)
|
||||
WenWangWen string // 文网文(HTML)
|
||||
SiteName string // 站点名称,默认 "MetaLab"
|
||||
SiteTagline string // 站点标语,默认 "下一代开发者社区"
|
||||
ContactEmail string // 联系/申诉邮箱,默认 "metazone@foxmail.com"
|
||||
Framework string // 附加标识,默认 "Framework: MetaGenesis"
|
||||
CopyrightStart string // 版权起始年份,默认 "2024"
|
||||
OperatorName string // 运营主体
|
||||
ICPNumber string // ICP 备案(HTML,含链接)
|
||||
ICPLicense string // ICP 经营许可证(HTML)
|
||||
PoliceNumber string // 公安备案(HTML)
|
||||
WenWangWen string // 文网文(HTML)
|
||||
AlgorithmFiling string // 算法备案(HTML)
|
||||
PrivacyURL string // 隐私政策(HTML)
|
||||
TermsURL string // 服务条款(HTML)
|
||||
PrivacyURL string // 隐私政策(HTML)
|
||||
TermsURL string // 服务条款(HTML)
|
||||
}
|
||||
|
||||
// SiteInfo 获取站点展示信息(优先 DB 设置,fallback 默认值)
|
||||
|
||||
Reference in New Issue
Block a user