feat: 换到 Gin 主流栈并补齐运维能力

HTTP 用 Gin,配置用 Viper,日志用 zap,数据用 sqlx;保留原有接口与会商行为。
顺带补上就绪探活、请求号、滚动日志、systemd 与 Dockerfile。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
gozerosandCursor committed 2026-11-04 09:51:41 +08:00
1 parent 0c45b86d67
commit bd427b57a1
26 files changed
+1213 -302

No files matched your search

+10 -13
View File
@@ -1,31 +1,28 @@
package api
import (
"encoding/json"
"net/http"
"github.com/gin-gonic/gin"
)
// ApiResponse 与 Java 一致:{ code, message, data };成功 code=0。
//
// 探活 /health、/ready 不走这个外壳,编排系统要直接读 ok 字段。
type ApiResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data"`
}
func writeJSON(w http.ResponseWriter, status int, body interface{}) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(body)
func OK(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, ApiResponse{Code: 0, Message: "ok", Data: data})
}
func OK(w http.ResponseWriter, data interface{}) {
writeJSON(w, http.StatusOK, ApiResponse{Code: 0, Message: "ok", Data: data})
func Created(c *gin.Context, data interface{}) {
c.JSON(http.StatusCreated, ApiResponse{Code: 0, Message: "ok", Data: data})
}
func Created(w http.ResponseWriter, data interface{}) {
writeJSON(w, http.StatusCreated, ApiResponse{Code: 0, Message: "ok", Data: data})
}
func Fail(w http.ResponseWriter, httpStatus, code int, msg string) {
writeJSON(w, httpStatus, ApiResponse{Code: code, Message: msg, Data: nil})
func Fail(c *gin.Context, httpStatus, code int, msg string) {
c.JSON(httpStatus, ApiResponse{Code: code, Message: msg, Data: nil})
}