A simple HTTP-based plugin system for Go.
- π Simple Plugin System: Easy-to-use API for creating and managing plugins
- π Type Safety: Generic-based functions with compile-time type checking
- π HTTP Communication: Reliable plugin communication over HTTP
- π Schema Validation: Automatic JSON schema generation and validation
- π Dynamic Loading: Load and execute plugins at runtime
- β‘ Performance: Minimal overhead with efficient execution
- π₯ Health Checks: Built-in health monitoring for plugin processes
go get github.com/henomis/pluggoCreate a plugin that implements a simple greeting function:
plugin/plugin.go
package main
import (
"context"
"github.com/henomis/pluggo"
)
type Input struct {
Name string `json:"name" jsonschema:"minLength=3"`
}
type Output struct {
Greeting string `json:"greeting"`
}
func Hello(ctx context.Context, in *Input) (*Output, error) {
return &Output{Greeting: "Hello, " + in.Name + "!"}, nil
}
func main() {
p := pluggo.NewPlugin()
// Create validator for input validation
v, err := pluggo.NewValidator(&Input{})
if err != nil {
panic(err)
}
// Register the function
p.AddFunction("hello", pluggo.NewFunctionHandler(Hello, v).Handler())
// Start the plugin server
err = p.Start()
if err != nil {
panic(err)
}
}Build the plugin:
go build -o plugin plugin.gomain.go
package main
import (
"context"
"fmt"
"github.com/henomis/pluggo"
)
type Input struct {
Name string `json:"name"`
}
type Output struct {
Greeting string `json:"greeting"`
}
func main() {
// Create client and load plugin
client := pluggo.New("./plugin/plugin")
err := client.Open(context.Background())
if err != nil {
panic(err)
}
defer client.Close()
// Create type-safe function
hello := pluggo.NewFunction[Input, Output]("hello", client.Connection())
// Call the function
result, err := hello.Call(&Input{Name: "World"})
if err != nil {
panic(err)
}
fmt.Println(result.Greeting) // Output: Hello, World!
}The repository includes several examples in the examples/ directory
Pluggo uses an HTTP-based architecture where:
- π Plugin Launch: Client launches plugin as separate process
- π‘ HTTP Communication: Plugin starts HTTP server and communicates port via stdout
- π Discovery: Client discovers available functions via
/_schemasendpoint - π₯ Health Monitoring: Built-in health checks via
/_healthzendpoint - β‘ Function Execution: Type-safe function calls via HTTP POST requests
βββββββββββββββ HTTP βββββββββββββββ
β Client ββββββββββββββΊβ Plugin β
β β β β
β βββββββββββ β β βββββββββββ β
β βFunction β β β βHandler β β
β β β ββββββββββββββΊβ β β β
β βββββββββββ β β βββββββββββ β
βββββββββββββββ βββββββββββββββ
p := pluggo.NewPlugin()p.AddFunction(name string, handler http.HandlerFunc)err := p.Start()client := pluggo.New(pluginPath string)err := client.Open(ctx context.Context)schemas, err := client.Schemas()fn := pluggo.NewFunction[InputType, OutputType](name string, connection *pluggo.Connection)result, err := fn.Call(input *InputType)schema, err := fn.Schema()Pluggo supports automatic input validation using JSON Schema tags:
type Input struct {
Name string `json:"name" jsonschema:"minLength=3,maxLength=50"`
Age int `json:"age" jsonschema:"minimum=0,maximum=120"`
Email string `json:"email" jsonschema:"format=email"`
}This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Go's native HTTP server for maximum performance
- Uses JSON Schema for robust input validation
- Inspired by modern microservices architecture patterns
Made with β€οΈ by henomis