You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of right now, the AddMiddleware API takes in an arbitrary string for method names. This is because at the time of writing this API, I did not know that method names could be taken by passing the method function in.
To preserve backwards compatibility, AddMiddleware will use reflect.Kind to ensure that the passed in type is only either a string or a function. If a string is provided, the old behavior will run. If a function is provided, the library will use the above method to get the method name, then execute the old behavior with that name. If any other type is given, the function will panic.
The text was updated successfully, but these errors were encountered:
diamondburned
changed the title
AddMiddleware to use Go methods instead of arbitrary strings
Bot: AddMiddleware to use Go methods instead of arbitrary strings
Sep 25, 2020
diamondburned
changed the title
Bot: AddMiddleware to use Go methods instead of arbitrary strings
Bot: v2: AddMiddleware to use Go methods instead of arbitrary strings
Nov 12, 2020
This commit adds subcommand aliases as well as additional code in
HelpGenerate to cover for both subcommand and command aliases.
A breaking change is that {,Must}RegisterSubcommandCustom methods are
now replaced with normal {,Must}RegisterSubcommand methods. This is
because they now use variadic strings, which could take 0, 1 or more
arguments.
This commit also allows AddMiddleware and similar methods to be given a
method directly:
sub.Plumb(cmds.PlumbedHandler)
sub.AddMiddleware(cmds.PlumbedHandler, cmds.plumbMiddleware)
This change closes issue #146.
Preamble
As of right now, the AddMiddleware API takes in an arbitrary string for method names. This is because at the time of writing this API, I did not know that method names could be taken by passing the method function in.
Code example:
As the example's output shows, some string manipulation will be needed.
Proposal
This issue proposes the new
AddMiddleware
API to have this function signature:To preserve backwards compatibility,
AddMiddleware
will usereflect.Kind
to ensure that the passed in type is only either a string or a function. If a string is provided, the old behavior will run. If a function is provided, the library will use the above method to get the method name, then execute the old behavior with that name. If any other type is given, the function will panic.An example of this API would be:
The text was updated successfully, but these errors were encountered: