ongdisheng commented on issue #7990:
URL: https://github.com/apache/apisix/issues/7990#issuecomment-3719758705
Hi, I would like to work on this issue. I have implemented a way that merges
the two directives using hash syntax, and I would appreciate feedback before
submitting a pull request.
## Proposed Approach
My approach consolidates `extra_init_by_lua_start` and `extra_init_by_lua`
into a single `extra_init_by_lua` directive that accepts a hash with `start`
and `end` keys. The `start` key contains code that runs before APISIX loads,
while the `end` key contains code that runs after APISIX initialization.
## Implementation Details
In `t/APISIX.pm`:
```lua
my $extra_init_by_lua = $block->extra_init_by_lua // {};
my $extra_init_start = ref($extra_init_by_lua) eq 'HASH' ?
($extra_init_by_lua->{start} // "") : "";
my $extra_init_end = ref($extra_init_by_lua) eq 'HASH' ?
($extra_init_by_lua->{end} // "") : $extra_init_by_lua;
init_by_lua_block {
require "resty.core"
$extra_init_start -- Runs before apisix loads
apisix = require("apisix")
apisix.http_init(args)
$extra_init_end -- Runs after apisix loads
}
```
In test files:
```lua
my $extra_init_by_lua = {
start => <<_EOC_
local schema = require("apisix.discovery.tars.schema")
schema.properties.minimum = 1
_EOC_
};
-- Or for code that runs after APISIX loads
my $extra_init_by_lua = {
end => <<_EOC_
local client = require("skywalking.client")
client.backendTimerDelay = 0.5
_EOC_
};
```
cc: @Baoyuantop
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]