Documentation
¶
Overview ¶
Package plugins provides various utilities and helpers for interacting with plugins, including sending HTTP requests to plugin endpoints, decoding request bodies, and validating plugin types against JSON schemas.
The package also includes mechanisms for managing plugin error handling, waiting for plugin readiness, and making plugin calls with various options.
Key components:
- **Call**: Makes HTTP requests to plugin endpoints with optional payloads, headers, and query parameters.
- **Error**: A custom error type for handling plugin-related errors in HTTP responses.
- **ValidatePlugin**: Validates an incoming raw type against a given JSON schema.
- **WaitForPlugin**: Waits for a plugin to become ready by making periodic health checks. Once the plugin is ready it sets up a client which can then be used to interact with said plugin.
Index ¶
- func Call(ctx context.Context, client *http.Client, locationType types.ConnectionType, ...) (err error)
- func DecodeJSONRequestBody[T any](writer http.ResponseWriter, request *http.Request) (*T, error)
- func GenerateJSONSchemaForType(obj runtime.Typed) ([]byte, error)
- func StartLogStreamer(ctx context.Context, plugin *types.Plugin)
- func ValidatePlugin(typ runtime.Typed, jsonSchema []byte) (bool, error)
- func WaitForPlugin(ctx context.Context, plugin *types.Plugin) (*http.Client, string, error)
- type CallOptionFn
- type CallOptions
- type Error
- type KV
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Call ¶
func Call(ctx context.Context, client *http.Client, locationType types.ConnectionType, location, endpoint, method string, opts ...CallOptionFn) (err error)
Call will use the plugin's constructed connection client to make a call to the specified endpoint. The result will be marshalled into the provided response if not nil.
func DecodeJSONRequestBody ¶
DecodeJSONRequestBody takes a request and any type and decodes the request's body into that type and returns the result.
func GenerateJSONSchemaForType ¶ added in v0.0.12
GenerateJSONSchemaForType takes a Type and uses reflection to generate a JSON Schema representation for it. It will also use the correct type representation as we don't marshal the type in object format.
func StartLogStreamer ¶
StartLogStreamer is intended to be launched when the plugin is started. It will continuously stream logs from the plugin to the context debug logger. Logs in the plugin has to be written to stderr. The expected logger using stderr should be set up like this:
logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelDebug, // debug level here is respected when sending this message.
}))
func ValidatePlugin ¶
ValidatePlugin will take a runtime Type and validate it against the given JSON Schema.
Types ¶
type CallOptionFn ¶
type CallOptionFn func(opt *CallOptions)
CallOptionFn defines a function that sets parameters for the Call method.
func WithHeader ¶
func WithHeader(header KV) CallOptionFn
WithHeader sets a specific header for the call.
func WithHeaders ¶
func WithHeaders(headers []KV) CallOptionFn
WithHeaders sets headers for the call.
func WithPayload ¶
func WithPayload(payload any) CallOptionFn
WithPayload sets up payload to send to the callee
func WithQueryParams ¶
func WithQueryParams(queryParams []KV) CallOptionFn
WithQueryParams sets url parameters for the call.
func WithResult ¶
func WithResult(result any) CallOptionFn
WithResult sets up a result that the call will marshal into.
type CallOptions ¶
CallOptions contains options for calling a plugin endpoint.