-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin): semplify the plugin API by using the callback directly
Signed-off-by: Vincenzo Palazzo <[email protected]>
- Loading branch information
1 parent
e3e06a2
commit ebe83ef
Showing
4 changed files
with
26 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
package plugin | ||
|
||
type rpcMethod[T any] struct { | ||
Name string `json:"name"` | ||
Usage string `json:"usage"` | ||
Description string `json:"description"` | ||
LongDescription string `json:"long_description"` | ||
callback RPCCommand[T] `json:"-"` | ||
Name string `json:"name"` | ||
Usage string `json:"usage"` | ||
Description string `json:"description"` | ||
LongDescription string `json:"long_description"` | ||
callback func(plugin *Plugin[T], request map[string]any) (map[string]any, error) `json:"-"` | ||
} | ||
|
||
func (instance *rpcMethod[T]) Call(plugin *Plugin[T], request map[string]any) (map[string]any, error) { | ||
return instance.callback.Call(plugin, request) | ||
return instance.callback(plugin, request) | ||
} | ||
|
||
type rpcNotification[T any] struct { | ||
onEvent string | ||
callback RPCEvent[T] | ||
callback func(plugin *Plugin[T], request map[string]any) | ||
} | ||
|
||
func (instance *rpcNotification[T]) Call(plugin *Plugin[T], request map[string]any) { | ||
instance.callback.Call(plugin, request) | ||
instance.callback(plugin, request) | ||
} | ||
|
||
type rpcHook[T any] struct { | ||
name string | ||
before []string | ||
after []string | ||
callback RPCCommand[T] | ||
callback func(plugin *Plugin[T], request map[string]any) (map[string]any, error) | ||
} | ||
|
||
func (instance *rpcHook[T]) Call(plugin *Plugin[T], request map[string]any) { | ||
if _, err := instance.callback.Call(plugin, request); err != nil { | ||
if _, err := instance.callback(plugin, request); err != nil { | ||
plugin.tracer.Infof("%s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters