-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add init handler and invoke it after config get deserialized #161
Comments
It would be great to have that capability. |
The initialization could be achieved with a function called only once when the access handler is invoked for the first time. |
Actually, this is what i'm doing right now as a workaround. But i think its not simple, e.g. you need to guard with mutex to prevent more than once initialization. Another thing regarding the current structure of the api to be considered is that it is quite easy to be trapped to do initialization inside the constructor, meanwhile the configuration is not yet loaded when the constructor is invoked so the initialization would be invalid. well at least thats what happened to me at first.
|
Hi @rucciva, due to the design of PDK and because it derives from the Lua plugin design, each plugin instance (the |
Hi @fffonion , thanks for responding, but forgive me, i'm not sure i understand your reasoning.
having an init won't make the plugin unable to handle a lots of requests, it would be executed only once before the handling of any request.
I'm not sure what you means with "stateful". The init that i propose was to derive or extend the state that was loaded from the config passed by kong one time only. For example there is no easy way to specify dynamic object as kong's config, so one of the possible way is to specify it as json/yaml string and decode that string to get back the dynamic object.
If the init is implemented and invoked here only after the config is loaded, won't that means it is "per-instance" level? |
@fffonion I think what they want is pretty much like a |
Sometimes, it is necesary to do some kine of initialization based on config of the plugin. Maybe invoke
instanceConfig.Init()
here?The text was updated successfully, but these errors were encountered: