Procházet zdrojové kódy

fix(internal/handler): 修复 IP 黑白名单处理中的参数绑定错误

- 在 AllowAndDenyIpHandler 的多个方法中,将 ctx.ShouldBind(req) 修改为 ctx.ShouldBind(&req)
- 这个修改确保了正确地将请求参数绑定到结构体指针,避免了潜在的数据绑定问题
fusu před 1 měsícem
rodič
revize
2792681ad7
1 změnil soubory, kde provedl 5 přidání a 5 odebrání
  1. 5 5
      internal/handler/allowanddenyip.go

+ 5 - 5
internal/handler/allowanddenyip.go

@@ -24,7 +24,7 @@ func NewAllowAndDenyIpHandler(
 
 func (h *AllowAndDenyIpHandler) GetAllowAndDenyIp(ctx *gin.Context) {
 	var req v1.AllowAndDenyIpRequest
-	if err := ctx.ShouldBind(req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
 		return
 	}
@@ -38,7 +38,7 @@ func (h *AllowAndDenyIpHandler) GetAllowAndDenyIp(ctx *gin.Context) {
 
 func (h *AllowAndDenyIpHandler) GetAllowAndDenyIpList(ctx *gin.Context) {
 	var req v1.AllowAndDenyIpRequest
-	if err := ctx.ShouldBind(req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
 		return
 	}
@@ -52,7 +52,7 @@ func (h *AllowAndDenyIpHandler) GetAllowAndDenyIpList(ctx *gin.Context) {
 
 func (h *AllowAndDenyIpHandler) AddAllowAndDenyIp(ctx *gin.Context) {
 	var req v1.AllowAndDenyIpRequest
-	if err := ctx.ShouldBind(req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
 		return
 	}
@@ -67,7 +67,7 @@ func (h *AllowAndDenyIpHandler) AddAllowAndDenyIp(ctx *gin.Context) {
 
 func (h *AllowAndDenyIpHandler) EditAllowAndDenyIp(ctx *gin.Context) {
 	var req v1.AllowAndDenyIpRequest
-	if err := ctx.ShouldBind(req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
 		return
 	}
@@ -81,7 +81,7 @@ func (h *AllowAndDenyIpHandler) EditAllowAndDenyIp(ctx *gin.Context) {
 
 func (h *AllowAndDenyIpHandler) DeleteAllowAndDenyIp(ctx *gin.Context) {
 	var req v1.DelAllowAndDenyIpRequest
-	if err := ctx.ShouldBind(req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
 		return
 	}