mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 18:10:25 +08:00
实现基本的匹配条件管理
This commit is contained in:
@@ -89,7 +89,7 @@ func (this *HTTPGzipDAO) ComposeGzipConfig(gzipId int64) (*serverconfigs.HTTPGzi
|
|||||||
config := &serverconfigs.HTTPGzipConfig{}
|
config := &serverconfigs.HTTPGzipConfig{}
|
||||||
config.Id = int64(gzip.Id)
|
config.Id = int64(gzip.Id)
|
||||||
config.IsOn = gzip.IsOn == 1
|
config.IsOn = gzip.IsOn == 1
|
||||||
if len(gzip.MinLength) > 0 && gzip.MinLength != "null" {
|
if IsNotNull(gzip.MinLength) {
|
||||||
minLengthConfig := &shared.SizeCapacity{}
|
minLengthConfig := &shared.SizeCapacity{}
|
||||||
err = json.Unmarshal([]byte(gzip.MinLength), minLengthConfig)
|
err = json.Unmarshal([]byte(gzip.MinLength), minLengthConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -97,7 +97,7 @@ func (this *HTTPGzipDAO) ComposeGzipConfig(gzipId int64) (*serverconfigs.HTTPGzi
|
|||||||
}
|
}
|
||||||
config.MinLength = minLengthConfig
|
config.MinLength = minLengthConfig
|
||||||
}
|
}
|
||||||
if len(gzip.MaxLength) > 0 && gzip.MaxLength != "null" {
|
if IsNotNull(gzip.MaxLength) {
|
||||||
maxLengthConfig := &shared.SizeCapacity{}
|
maxLengthConfig := &shared.SizeCapacity{}
|
||||||
err = json.Unmarshal([]byte(gzip.MaxLength), maxLengthConfig)
|
err = json.Unmarshal([]byte(gzip.MaxLength), maxLengthConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -106,20 +106,33 @@ func (this *HTTPGzipDAO) ComposeGzipConfig(gzipId int64) (*serverconfigs.HTTPGzi
|
|||||||
config.MaxLength = maxLengthConfig
|
config.MaxLength = maxLengthConfig
|
||||||
}
|
}
|
||||||
config.Level = types.Int8(gzip.Level)
|
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
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建Gzip
|
// 创建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 := NewHTTPGzipOperator()
|
||||||
op.State = HTTPGzipStateEnabled
|
op.State = HTTPGzipStateEnabled
|
||||||
op.IsOn = true
|
op.IsOn = true
|
||||||
op.Level = level
|
op.Level = level
|
||||||
if len(minLengthJSON) > 0 {
|
if len(minLengthJSON) > 0 {
|
||||||
op.MinLength = string(minLengthJSON)
|
op.MinLength = JSONBytes(minLengthJSON)
|
||||||
}
|
}
|
||||||
if len(maxLengthJSON) > 0 {
|
if len(maxLengthJSON) > 0 {
|
||||||
op.MaxLength = string(maxLengthJSON)
|
op.MaxLength = JSONBytes(maxLengthJSON)
|
||||||
|
}
|
||||||
|
if len(condGroupsJSON) > 0 {
|
||||||
|
op.CondGroups = JSONBytes(condGroupsJSON)
|
||||||
}
|
}
|
||||||
_, err := this.Save(op)
|
_, err := this.Save(op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -129,7 +142,7 @@ func (this *HTTPGzipDAO) CreateGzip(level int, minLengthJSON []byte, maxLengthJS
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 修改Gzip
|
// 修改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 {
|
if gzipId <= 0 {
|
||||||
return errors.New("invalid gzipId")
|
return errors.New("invalid gzipId")
|
||||||
}
|
}
|
||||||
@@ -137,10 +150,13 @@ func (this *HTTPGzipDAO) UpdateGzip(gzipId int64, level int, minLengthJSON []byt
|
|||||||
op.Id = gzipId
|
op.Id = gzipId
|
||||||
op.Level = level
|
op.Level = level
|
||||||
if len(minLengthJSON) > 0 {
|
if len(minLengthJSON) > 0 {
|
||||||
op.MinLength = string(minLengthJSON)
|
op.MinLength = JSONBytes(minLengthJSON)
|
||||||
}
|
}
|
||||||
if len(maxLengthJSON) > 0 {
|
if len(maxLengthJSON) > 0 {
|
||||||
op.MaxLength = string(maxLengthJSON)
|
op.MaxLength = JSONBytes(maxLengthJSON)
|
||||||
|
}
|
||||||
|
if len(condGroupsJSON) > 0 {
|
||||||
|
op.CondGroups = JSONBytes(condGroupsJSON)
|
||||||
}
|
}
|
||||||
_, err := this.Save(op)
|
_, err := this.Save(op)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -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 {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user