Skip to content
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

change: added an example of plugin. #2

Merged
merged 4 commits into from
May 6, 2019
Merged

change: added an example of plugin. #2

merged 4 commits into from
May 6, 2019

Conversation

membphis
Copy link
Member

@membphis membphis commented May 6, 2019

No description provided.

function _M.check_args(arg, scheme)
for k, v in pairs(scheme) do
if not typeof[v](arg[k]) then
return nil, "key [" .. k .. "] should be a " .. v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to print the value of the key, which is friendly for debugging.

}


return _M
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check and add license of this file, and do we really need so many types?

}


local _M = {VER = 0.1}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use version = 0.1

function _M.check_args(config)
local ok, err = plugin.check_args(config, args_schema)
if not ok then
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think return false, err is better


local ok, err = _M.check_args(config)
if not ok then
return ok, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local args_schema = {
i = "int", -- value list: apimeta.comm.typeof#92
s = "string",
t = "table",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to set the default value or max value or min value in the schema? I think we should use dict as value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example name = { type = "string", default = 'test' }



function _M.check_args(arg, scheme)
for k, v in pairs(scheme) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pairs can not be JIT, we should avoid to use it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is not a hot path, it's fine.



local _M = {
log = log,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@membphis membphis merged commit 1703fc6 into master May 6, 2019
@membphis membphis deleted the plugin-example branch May 6, 2019 06:36
bzp2010 referenced this pull request in bzp2010/apisix Jan 26, 2022
bzp2010 referenced this pull request in bzp2010/apisix Jan 26, 2022
bzp2010 referenced this pull request in bzp2010/apisix Jan 26, 2022
bzp2010 referenced this pull request in bzp2010/apisix Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants