-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
lua/apimeta/plugin.lua
Outdated
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should keep the same style with https://github.com/iresty/apimeta/pull/2/files#diff-b7c0a61beccdbe9021dc64ff808f0e91R17
local args_schema = { | ||
i = "int", -- value list: apimeta.comm.typeof#92 | ||
s = "string", | ||
t = "table", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.