From eb38e7d0500a5b71b89644a96fbed00ff27f17e9 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 20 Sep 2020 14:48:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=BB=9F=E8=AE=A1=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/http_web_dao.go | 26 +++++++++++++++++++++++ internal/db/models/http_web_model.go | 2 ++ internal/rpc/services/service_http_web.go | 15 +++++++++++++ 3 files changed, 43 insertions(+) diff --git a/internal/db/models/http_web_dao.go b/internal/db/models/http_web_dao.go index 9cba2f9c..eb93a46d 100644 --- a/internal/db/models/http_web_dao.go +++ b/internal/db/models/http_web_dao.go @@ -146,6 +146,16 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon config.AccessLog = accessLogConfig } + // 统计配置 + if IsNotNull(web.Stat) { + statConfig := &serverconfigs.HTTPStatConfig{} + err = json.Unmarshal([]byte(web.Stat), statConfig) + if err != nil { + return nil, err + } + config.Stat = statConfig + } + // TODO 更多配置 return config, nil @@ -291,6 +301,22 @@ func (this *HTTPWebDAO) UpdateWebAccessLogConfig(webId int64, accessLogJSON []by return this.NotifyUpdating(webId) } +// 更改统计配置 +func (this *HTTPWebDAO) UpdateWebStat(webId int64, statJSON []byte) error { + if webId <= 0 { + return errors.New("invalid webId") + } + op := NewHTTPWebOperator() + op.Id = webId + op.Stat = JSONBytes(statJSON) + _, err := this.Save(op) + if err != nil { + return err + } + + return this.NotifyUpdating(webId) +} + // 通知更新 func (this *HTTPWebDAO) NotifyUpdating(webId int64) error { err := SharedServerDAO.UpdateServerIsUpdatingWithWebId(webId) diff --git a/internal/db/models/http_web_model.go b/internal/db/models/http_web_model.go index a3186b48..8b816314 100644 --- a/internal/db/models/http_web_model.go +++ b/internal/db/models/http_web_model.go @@ -23,6 +23,7 @@ type HTTPWeb struct { RequestHeaderPolicyId uint32 `field:"requestHeaderPolicyId"` // Request Header策略ID ResponseHeaderPolicyId uint32 `field:"responseHeaderPolicyId"` // Response Header策略 AccessLog string `field:"accessLog"` // 访问日志配置 + Stat string `field:"stat"` // 统计配置 } type HTTPWebOperator struct { @@ -47,6 +48,7 @@ type HTTPWebOperator struct { RequestHeaderPolicyId interface{} // Request Header策略ID ResponseHeaderPolicyId interface{} // Response Header策略 AccessLog interface{} // 访问日志配置 + Stat interface{} // 统计配置 } func NewHTTPWebOperator() *HTTPWebOperator { diff --git a/internal/rpc/services/service_http_web.go b/internal/rpc/services/service_http_web.go index 76656f1f..b690595f 100644 --- a/internal/rpc/services/service_http_web.go +++ b/internal/rpc/services/service_http_web.go @@ -177,3 +177,18 @@ func (this *HTTPWebService) UpdateHTTPAccessLog(ctx context.Context, req *pb.Upd } return rpcutils.RPCUpdateSuccess() } + +// 更改统计配置 +func (this *HTTPWebService) UpdateHTTPStat(ctx context.Context, req *pb.UpdateHTTPStatRequest) (*pb.RPCUpdateSuccess, error) { + // 校验请求 + _, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin) + if err != nil { + return nil, err + } + + err = models.SharedHTTPWebDAO.UpdateWebStat(req.WebId, req.StatJSON) + if err != nil { + return nil, err + } + return rpcutils.RPCUpdateSuccess() +}