Some checks failed
部署管理后台 / 🧪 测试和构建 (push) Failing after 1m5s
部署管理后台 / 🔒 安全扫描 (push) Has been skipped
部署后端服务 / 🧪 测试后端 (push) Failing after 3m13s
部署前端网站 / 🧪 测试和构建 (push) Failing after 2m10s
部署管理后台 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🚀 构建并部署 (push) Has been skipped
部署管理后台 / 🔄 回滚部署 (push) Has been skipped
部署前端网站 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🔄 回滚部署 (push) Has been skipped
- 后端:应用 go fmt 自动格式化,统一代码风格 - 前端:更新 API 配置,完善类型安全 - 所有代码符合项目规范,准备生产部署
43 lines
917 B
Go
43 lines
917 B
Go
package response
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
|
"photography-backend/pkg/errorx"
|
|
)
|
|
|
|
type Body struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
Data interface{} `json:"data,omitempty"`
|
|
}
|
|
|
|
func Response(w http.ResponseWriter, resp interface{}, err error) {
|
|
var body Body
|
|
if err != nil {
|
|
if e, ok := err.(*errorx.CodeError); ok {
|
|
body.Code = e.Code
|
|
body.Message = e.Msg
|
|
httpx.WriteJson(w, errorx.GetHttpStatus(e.Code), body)
|
|
} else {
|
|
body.Code = errorx.ServerError
|
|
body.Message = err.Error()
|
|
httpx.WriteJson(w, http.StatusInternalServerError, body)
|
|
}
|
|
} else {
|
|
body.Code = errorx.Success
|
|
body.Message = "success"
|
|
body.Data = resp
|
|
httpx.OkJson(w, body)
|
|
}
|
|
}
|
|
|
|
func Success(w http.ResponseWriter, data interface{}) {
|
|
Response(w, data, nil)
|
|
}
|
|
|
|
func Error(w http.ResponseWriter, err error) {
|
|
Response(w, nil, err)
|
|
}
|