From a287c03ca4abf4d3c8ba3b593408397b791be159 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Wed, 8 Nov 2023 17:57:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A1=E6=95=B0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drivers/plugins/counter/executor.go | 10 +++++----- drivers/plugins/counter/key.go | 12 ++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/plugins/counter/executor.go b/drivers/plugins/counter/executor.go index 5efd9a2c..3f9a80b8 100644 --- a/drivers/plugins/counter/executor.go +++ b/drivers/plugins/counter/executor.go @@ -51,19 +51,19 @@ func (b *executor) DoHttpFilter(ctx http_service.IHttpContext, next eocontext.IC b.client = scope_manager.Auto[counter.IClient](b.clientID, "counter") b.counterPusher = scope_manager.Auto[counter.ICountPusher](b.countPusherID, "counter-pusher") }) - body := ctx.Response().GetBody() - if len(body) < 1 { + + variables, ok := b.keyGenerate.Variables(ctx) + if !ok { return next.DoChain(ctx) } - key := b.keyGenerate.Key(ctx) ct, has := b.counters.Get(key) if !has { switch b.countMode { case localMode: - ct = NewLocalCounter(key, b.keyGenerate.Variables(ctx), b.client, b.counterPusher) + ct = NewLocalCounter(key, variables, b.client, b.counterPusher) case redisMode: - ct = NewRedisCounter(key, b.keyGenerate.Variables(ctx), b.cache, b.client, b.counterPusher) + ct = NewRedisCounter(key, variables, b.cache, b.client, b.counterPusher) } b.counters.Set(key, ct) } diff --git a/drivers/plugins/counter/key.go b/drivers/plugins/counter/key.go index 807aed96..4ee9bbc5 100644 --- a/drivers/plugins/counter/key.go +++ b/drivers/plugins/counter/key.go @@ -13,7 +13,7 @@ var _ IKeyGenerator = (*keyGenerate)(nil) type IKeyGenerator interface { Key(ctx http_service.IHttpContext) string - Variables(ctx http_service.IHttpContext) eosc.Untyped[string, string] + Variables(ctx http_service.IHttpContext) (eosc.Untyped[string, string], bool) } func newKeyGenerate(key string) *keyGenerate { @@ -43,13 +43,17 @@ type keyGenerate struct { variables []string } -func (k *keyGenerate) Variables(ctx http_service.IHttpContext) eosc.Untyped[string, string] { +func (k *keyGenerate) Variables(ctx http_service.IHttpContext) (eosc.Untyped[string, string], bool) { variables := eosc.BuildUntyped[string, string]() entry := ctx.GetEntry() for _, v := range k.variables { - variables.Set(fmt.Sprintf("$%s", v), eosc.ReadStringFromEntry(entry, v)) + value := eosc.ReadStringFromEntry(entry, v) + if value == "" { + return nil, false + } + variables.Set(fmt.Sprintf("$%s", v), value) } - return variables + return variables, true } func (k *keyGenerate) Key(ctx http_service.IHttpContext) string {