统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
This commit is contained in:
1 parent
28cd9d3406
commit
f60d3b0880
603 files changed
+2351
-660
No files matched your search
@@ -0,0 +1,22 @@
|
||||
package response
|
||||
|
||||
// ConfigErrorData 是配置 API 的统一错误载荷,不包含底层错误、路径、密文或第三方响应正文。
|
||||
type ConfigErrorData struct {
|
||||
Code string `json:"code"`
|
||||
RequestID string `json:"requestId"`
|
||||
Fields map[string]string `json:"fields,omitempty"`
|
||||
}
|
||||
|
||||
// ConfigErrorNumber 保留旧 errorNo 外壳,同时让 HTTP 状态承担标准语义。
|
||||
func ConfigErrorNumber(httpStatus int) int {
|
||||
switch {
|
||||
case httpStatus >= 500:
|
||||
return ServerError
|
||||
case httpStatus == 401:
|
||||
return NeedLogin
|
||||
case httpStatus == 403:
|
||||
return NoAccessPrivileges
|
||||
default:
|
||||
return ParamsError
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package response
|
||||
|
||||
import "git.pcux.cn/xuans/Smail/models"
|
||||
|
||||
type EmailResponseData struct {
|
||||
models.Email `xorm:"extends"`
|
||||
IsRead int8 `json:"is_read"`
|
||||
IsDeleted int8 `json:"-"`
|
||||
SerialNumber int `json:"serial_number"`
|
||||
UeId int `json:"ue_id"`
|
||||
}
|
||||
|
||||
type UserEmailUIDData struct {
|
||||
models.UserEmail `xorm:"extends"`
|
||||
SerialNumber int `json:"serial_number"`
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
NeedSetup = 402
|
||||
NeedLogin = 403
|
||||
NoAccessPrivileges = 405
|
||||
ParamsError = 100
|
||||
ServerError = 500
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
ErrorNo int `json:"errorNo"`
|
||||
ErrorMsg string `json:"errorMsg"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
func (p *Response) FPrint(w http.ResponseWriter) {
|
||||
bytesData, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("serialize HTTP response failed")
|
||||
http.Error(w, "\u54cd\u5e94\u5e8f\u5217\u5316\u5931\u8d25", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
if _, err := w.Write(bytesData); err != nil {
|
||||
log.WithError(err).Error("write HTTP response failed")
|
||||
}
|
||||
}
|
||||
|
||||
func NewSuccessResponse(data any) *Response {
|
||||
return &Response{
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func NewErrorResponse(errorNo int, errorMsg string, data any) *Response {
|
||||
return &Response{
|
||||
ErrorNo: errorNo,
|
||||
ErrorMsg: errorMsg,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user