apisix icon indicating copy to clipboard operation
apisix copied to clipboard

chore: `limit-req` plugin code optimization

Open Firstsawyou opened this issue 6 years ago • 4 comments

Issue description

This part of the code ( https://github.com/apache/apisix/blob/master/apisix/plugins/limit-req.lua#L70-L80) can be replaced with "local key = (ctx.var[conf.key] or "") .. ctx.conf_type .. ctx.conf_version" .

Firstsawyou avatar Oct 17 '20 07:10 Firstsawyou

Issue description

This part of the code ( https://github.com/apache/apisix/blob/master/apisix/plugins/limit-req.lua#L70-L80) can be replaced with "local key = (ctx.var[conf.key] or "") .. ctx.conf_type .. ctx.conf_version" . If i want to use service_name to limit,i just modify key;just like so service-name

LY-GO avatar Oct 22 '20 09:10 LY-GO

with "local key = (ctx.var[conf.key] or "") .. ctx.conf_type .. ctx.conf_version" .

this style can support service_id and consumer_id at the same time. @LY-GO

membphis avatar Oct 23 '20 14:10 membphis

with "local key = (ctx.var[conf.key] or "") .. ctx.conf_type .. ctx.conf_version" .

this style can support service_id and consumer_id at the same time. @LY-GO That means that i don't need to restart to define key,i can directly use original way to accomplish my demand;But other plugins,just like limit-conn and limit-count ,is ok?

LY-GO avatar Oct 23 '20 15:10 LY-GO

That means that i don't need to restart to define key,i can directly use original way to accomplish my demand;But other plugins,just like limit-conn and limit-count ,is ok?

the defined key is a whitelist, we need to enable it first.

and then we can use service_id or consumer_id.

the current code style, we can remove those, they are useless now. https://github.com/apache/apisix/blob/master/apisix/plugins/limit-req.lua#L71-L78

membphis avatar Oct 24 '20 02:10 membphis