From b2fa7c01ba9ffb0af1edab83b0c09a954ca67d92 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Tue, 29 Sep 2020 11:28:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=9F=BA=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=9D=A1=E4=BB=B6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/http_gzip_dao.go | 32 +++++++++++++++++------ internal/rpc/services/sevice_http_gzip.go | 4 +-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/internal/db/models/http_gzip_dao.go b/internal/db/models/http_gzip_dao.go index 7135efbd..6553dd8b 100644 --- a/internal/db/models/http_gzip_dao.go +++ b/internal/db/models/http_gzip_dao.go @@ -89,7 +89,7 @@ func (this *HTTPGzipDAO) ComposeGzipConfig(gzipId int64) (*serverconfigs.HTTPGzi config := &serverconfigs.HTTPGzipConfig{} config.Id = int64(gzip.Id) config.IsOn = gzip.IsOn == 1 - if len(gzip.MinLength) > 0 && gzip.MinLength != "null" { + if IsNotNull(gzip.MinLength) { minLengthConfig := &shared.SizeCapacity{} err = json.Unmarshal([]byte(gzip.MinLength), minLengthConfig) if err != nil { @@ -97,7 +97,7 @@ func (this *HTTPGzipDAO) ComposeGzipConfig(gzipId int64) (*serverconfigs.HTTPGzi } config.MinLength = minLengthConfig } - if len(gzip.MaxLength) > 0 && gzip.MaxLength != "null" { + if IsNotNull(gzip.MaxLength) { maxLengthConfig := &shared.SizeCapacity{} err = json.Unmarshal([]byte(gzip.MaxLength), maxLengthConfig) if err != nil { @@ -106,20 +106,33 @@ func (this *HTTPGzipDAO) ComposeGzipConfig(gzipId int64) (*serverconfigs.HTTPGzi config.MaxLength = maxLengthConfig } config.Level = types.Int8(gzip.Level) + + if IsNotNull(gzip.CondGroups) { + groups := []*shared.HTTPRequestCondGroup{} + err = json.Unmarshal([]byte(gzip.CondGroups), &groups) + if err != nil { + return nil, err + } + config.CondGroups = groups + } + return config, nil } // 创建Gzip -func (this *HTTPGzipDAO) CreateGzip(level int, minLengthJSON []byte, maxLengthJSON []byte) (int64, error) { +func (this *HTTPGzipDAO) CreateGzip(level int, minLengthJSON []byte, maxLengthJSON []byte, condGroupsJSON []byte) (int64, error) { op := NewHTTPGzipOperator() op.State = HTTPGzipStateEnabled op.IsOn = true op.Level = level if len(minLengthJSON) > 0 { - op.MinLength = string(minLengthJSON) + op.MinLength = JSONBytes(minLengthJSON) } if len(maxLengthJSON) > 0 { - op.MaxLength = string(maxLengthJSON) + op.MaxLength = JSONBytes(maxLengthJSON) + } + if len(condGroupsJSON) > 0 { + op.CondGroups = JSONBytes(condGroupsJSON) } _, err := this.Save(op) if err != nil { @@ -129,7 +142,7 @@ func (this *HTTPGzipDAO) CreateGzip(level int, minLengthJSON []byte, maxLengthJS } // 修改Gzip -func (this *HTTPGzipDAO) UpdateGzip(gzipId int64, level int, minLengthJSON []byte, maxLengthJSON []byte) error { +func (this *HTTPGzipDAO) UpdateGzip(gzipId int64, level int, minLengthJSON []byte, maxLengthJSON []byte, condGroupsJSON []byte) error { if gzipId <= 0 { return errors.New("invalid gzipId") } @@ -137,10 +150,13 @@ func (this *HTTPGzipDAO) UpdateGzip(gzipId int64, level int, minLengthJSON []byt op.Id = gzipId op.Level = level if len(minLengthJSON) > 0 { - op.MinLength = string(minLengthJSON) + op.MinLength = JSONBytes(minLengthJSON) } if len(maxLengthJSON) > 0 { - op.MaxLength = string(maxLengthJSON) + op.MaxLength = JSONBytes(maxLengthJSON) + } + if len(condGroupsJSON) > 0 { + op.CondGroups = JSONBytes(condGroupsJSON) } _, err := this.Save(op) return err diff --git a/internal/rpc/services/sevice_http_gzip.go b/internal/rpc/services/sevice_http_gzip.go index 9d6cd996..13933479 100644 --- a/internal/rpc/services/sevice_http_gzip.go +++ b/internal/rpc/services/sevice_http_gzip.go @@ -42,7 +42,7 @@ func (this *HTTPGzipService) CreateHTTPGzip(ctx context.Context, req *pb.CreateH } } - gzipId, err := models.SharedHTTPGzipDAO.CreateGzip(int(req.Level), minLengthJSON, maxLengthJSON) + gzipId, err := models.SharedHTTPGzipDAO.CreateGzip(int(req.Level), minLengthJSON, maxLengthJSON, req.CondGroupsJSON) if err != nil { return nil, err } @@ -100,7 +100,7 @@ func (this *HTTPGzipService) UpdateHTTPGzip(ctx context.Context, req *pb.UpdateH } } - err = models.SharedHTTPGzipDAO.UpdateGzip(req.GzipId, int(req.Level), minLengthJSON, maxLengthJSON) + err = models.SharedHTTPGzipDAO.UpdateGzip(req.GzipId, int(req.Level), minLengthJSON, maxLengthJSON, req.CondGroupsJSON) if err != nil { return nil, err }