Ways to implement Host-Plugin interaction #47
namit-chandwani
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There are many ways by which a host can interact with plugins and these can be divided mainly into 2 categories:
Multi-process (or external process) architecture: Plugins run as separate processes and the host process communicates with the plugins using various communication techniques (for eg. RPC).
Single process (or in-process) architecture: Plugins and the host run on the same process.
These approaches are described in detail below:
1. Multi-process architecture
1.1) Using RPC via stdin/stdout
Description:
Example: natefinch/pie
1.2) Using RPC via network
Description:
Example: hashicorp/go-plugin
Pros and cons of both the above approaches that involve RPC-based communication:
Pros:
Cons:
1.3) Via message queue
Description:
Message queue systems, particularly brokerless ones, provide a great foundation for developing plugin systems. They can be conveniently converted to a plugin architecture.
2. Single process architecture
2.1) Using the Golang Plugin package
Description:
Golang Plugins is a way of extending Golang applications natively
This approach uses the ability of Go packages that enable them to be compiled as shared object (.so) libraries and to be loaded dynamically at run time
These work by compiling plugins in the following way:
This build mode can output a
.so
file with symbols that the host CLI can load dynamically.Pros:
Cons:
Examples: Krakend, Gotify
2.2) Embedded scripting
Description:
Pros:
Cons:
Examples:
2.3) Including plugins at compile time
Description:
Pros:
Cons:
Example:
HTTP middleware is one of the most frequent forms of compile-time plugins. The
net/http
package of Golang makes it easier to add new handlers to an HTTP server by following these steps:Handler
interface, or functions that have the signature:func(w http.ResponseWriter, r *http.Request)
net/http
package into the applicationhttp.Handle(<pattern>, <pkg_name.handler_name>)
orhttp.HandleFunc(<pattern>, <pkg_name.handlefunc_name>)
2.4) Using Goroutines (Not recommended in most cases)
2.5) Using Config files (Not recommended in most cases)
Beta Was this translation helpful? Give feedback.
All reactions