feat(backend): unified response helpers, refresh token, security hardening

- new resp package (OK/Page/Fail/BadRequest/.../InternalErr): unified error
  envelope {detail, code?}, sanitized 500s (full error logged server-side,
  generic message to client - stops DB error leakage), pagination envelope
  {items,total,page,page_size}; migrate 200+ inline c.JSON error sites
- refresh token: 7d rotation tokens (SHA-256 hashed at rest), public
  POST /auth/refresh with single-use rotation, POST /auth/logout revokes
  all user refresh tokens (endpoint previously missing - frontend 404)
- security: gh-ost command line password masked in task status payload;
  Instance.MarshalJSON guarantees encrypted passwords never leave the API
  (removes reliance on per-handler manual masking); production (DEBUG=false)
  with default JWT secret now auto-generates and persists a random secret
- safe.Go recover wrapper for background goroutines (instance probe,
  gh-ost async)
- delete dead service layer (zero callers)
- fix pre-existing go vet unkeyed bson.E literals
This commit is contained in:
Logan.Li committed 2026-10-26 17:21:00 +08:00
1 parent d5b8b8116c
commit 16f1f7d65f
26 files changed
+916 -963

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
// Package safe 提供带 recover 的后台 goroutine 包装:
// 裸 go func() 一旦 panic 会击穿整个进程,后台任务必须经由 safe.Go 启动。
package safe
import (
"log"
"runtime/debug"
)
// Go 启动带 recover 的后台任务;panic 只记录堆栈,不影响进程。
func Go(name string, fn func()) {
go func() {
defer func() {
if r := recover(); r != nil {
log.Printf("[safe:%s] panic recovered: %v\n%s", name, r, debug.Stack())
}
}()
fn()
}()
}