-
Notifications
You must be signed in to change notification settings - Fork 98
add options to set custom namespace separator and a method name transformer #131
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 options to set custom namespace separator and a method name transformer #131
Conversation
Stebalien
left a comment
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.
This seems like a reasonable improvement. Thanks!
handler.go
Outdated
| if s.methodNameTransformer != nil { | ||
| method.Name = s.methodNameTransformer(method.Name) | ||
| } | ||
|
|
||
| s.methods[namespace+"."+method.Name] = methodHandler{ | ||
| s.methods[namespace+s.separator+method.Name] = methodHandler{ |
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 about letting the user control everything with a "method name formatter". I.e.:
- Define a
WithMethodNameFormatteroption that takes afunc(namespace, method string) string. - Default to
func(namespace, method) string { return namespace + "." + name }.
That way the user can combine the method name and namespace in any way they want.
Also, please don't modify method.Name (it's probably safe, but I would avoid 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.
E.g., in case the user wants something like method.namepace or /namespace/method etc.
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.
s.methods[s.methodNameFormatter(namespace, method.Name)] = methodHandler{
paramReceivers: recvs,
nParams: ins,
handlerFunc: method.Func,
receiver: val,
hasCtx: hasCtx,
hasRawParams: hasRawParams,
errOut: errOut,
valOut: valOut,
}add a formatter handler now and defaults to namespace.method
Stebalien
left a comment
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.
Thanks!
helps create eth_* friendly rpc methods by allowing custom options
example: