统一严格解析管理接口 JSON

This commit is contained in:
xuans committed 2026-08-30 20:10:06 +08:00
1 parent e178f9fcf0
commit be84ecfb91
7 files changed
+104 -22

No files matched your search

+5 -10
View File
@@ -332,9 +332,8 @@ func (s *Server) listDomains(c *gin.Context) {
}
func (s *Server) createDomain(c *gin.Context) {
limitJSONBody(c)
var request domainRequest
if err := c.ShouldBindJSON(&request); err != nil {
if err := bindJSON(c, &request, jsonRequestBodyLimit); err != nil {
s.writeError(c, http.StatusBadRequest, "请求参数无效", err)
return
}
@@ -355,9 +354,8 @@ func (s *Server) createDomain(c *gin.Context) {
}
func (s *Server) updateDomain(c *gin.Context) {
limitJSONBody(c)
var request domainRequest
if err := c.ShouldBindJSON(&request); err != nil {
if err := bindJSON(c, &request, jsonRequestBodyLimit); err != nil {
s.writeError(c, http.StatusBadRequest, "请求参数无效", err)
return
}
@@ -466,13 +464,12 @@ func (s *Server) getServer(c *gin.Context) {
}
func (s *Server) createServer(c *gin.Context) {
limitJSONBody(c)
if s.servers == nil {
s.writeError(c, http.StatusNotImplemented, "服务器管理接口尚未配置", errors.New("服务器仓储未配置"))
return
}
var request serverRequest
if err := c.ShouldBindJSON(&request); err != nil {
if err := bindJSON(c, &request, jsonRequestBodyLimit); err != nil {
s.writeError(c, http.StatusBadRequest, "请求参数无效", err)
return
}
@@ -490,13 +487,12 @@ func (s *Server) createServer(c *gin.Context) {
}
func (s *Server) updateServer(c *gin.Context) {
limitJSONBody(c)
if s.servers == nil {
s.writeError(c, http.StatusNotImplemented, "服务器管理接口尚未配置", errors.New("服务器仓储未配置"))
return
}
var request serverRequest
if err := c.ShouldBindJSON(&request); err != nil {
if err := bindJSON(c, &request, jsonRequestBodyLimit); err != nil {
s.writeError(c, http.StatusBadRequest, "请求参数无效", err)
return
}
@@ -570,7 +566,6 @@ func (s *Server) listDomainServers(c *gin.Context) {
}
func (s *Server) replaceDomainServers(c *gin.Context) {
limitJSONBody(c)
if s.servers == nil {
s.writeError(c, http.StatusNotImplemented, "服务器管理接口尚未配置", errors.New("服务器仓储未配置"))
return
@@ -584,7 +579,7 @@ func (s *Server) replaceDomainServers(c *gin.Context) {
return
}
var request domainServersRequest
if err := c.ShouldBindJSON(&request); err != nil {
if err := bindJSON(c, &request, jsonRequestBodyLimit); err != nil {
s.writeError(c, http.StatusBadRequest, "请求参数无效", err)
return
}