Explorar o código

fix(admin): 修复删除已绑定 IP 时出现的错误

- 在删除 IP 前增加对 HostId 的检查,如果 HostId 不为 0,则表示该 IP 已被绑定
- 如果 IP 已被绑定,返回错误信息"该 IP 已被绑定,无法删除"
- 此修改防止了删除已绑定 IP 时出现的 panic 错误
fusu hai 3 semanas
pai
achega
565351ab5a
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      internal/service/admin/gatewayipadmin.go

+ 8 - 0
internal/service/admin/gatewayipadmin.go

@@ -102,6 +102,10 @@ func (s *gatewayIpAdminService) DeleteGatewayIp(ctx context.Context,id int64) er
 	if err != nil {
 		return err
 	}
+	if oldData.HostId != 0 {
+		return fmt.Errorf("该IP已被绑定,无法删除")
+	}
+
 	// 启动网关组IP
 	if oldData.NodeArea != "" {
 		err := s.sendIp(ctx,oldData.Ip,"deleteIp",oldData.NodeArea)
@@ -122,6 +126,10 @@ func (s *gatewayIpAdminService) DeleteGatewayIps(ctx context.Context, ids []int6
 			return err
 		}
 
+		if oldData.HostId != 0 {
+			return fmt.Errorf("该IP已被绑定,无法删除")
+		}
+
 		// 启动网关组IP
 		if oldData.NodeArea != "" {
 			err := s.sendIp(ctx,oldData.Ip,"deleteIp",oldData.NodeArea)