jsonline

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jsonline binds ext.io.pc/v1 to bounded newline-delimited JSON over a caller-owned duplex connection (for example, local IPC or process pipes). It neither starts processes nor chooses native endpoints.

Index

Constants

View Source
const FailureCode = "provider_error"

FailureCode is the code of the RemoteError produced for an ordinary error.

View Source
const MaxFailureMessageBytes = 4096

MaxFailureMessageBytes bounds an ordinary error's message.

Variables

This section is empty.

Functions

func NewFuncGuest

func NewFuncGuest(descriptor plugin.Descriptor, fn Func, options FuncOptions) (*plugin.Guest, error)

NewFuncGuest adapts fn to a guest endpoint for descriptor. An error that is (or wraps) a *plugin.RemoteError is sent as is; any other error becomes RemoteError{Code: FailureCode, Message: err.Error()} cut to MaxFailureMessageBytes on a character boundary, or a generic message when RedactErrors is set.

func Profile

func Profile() plugin.BackendProfile

func Serve

func Serve(ctx context.Context, conn io.ReadWriteCloser, descriptor plugin.Descriptor, handler Handler) error

Serve requires hello first and validates every subsequent request against the descriptor before calling handler. Calls are sequential. It owns conn; cancellation closes it. Domain payloads and error text are never logged.

func ServeFunc

func ServeFunc(ctx context.Context, descriptor plugin.Descriptor, fn Func, options FuncOptions) error

ServeFunc serves fn for descriptor on this process's stdin and stdout until the stream ends; see ServeStdio for the stream rules. Call once from main.

func ServeGuest

func ServeGuest(ctx context.Context, conn io.ReadWriteCloser, guest plugin.Endpoint) error

ServeGuest binds a shared guest endpoint to a JSON-line connection. This owns only conn; the embedding application owns the endpoint's lifecycle.

A reader goroutine routes frames: requests go to the call loop, which handles one call at a time, and reverse responses go to the reverse call that waits for them. A handler that blocks on a reverse call therefore never stops the reader, so a serialized connection cannot deadlock. Handlers reach the host with plugin.ReverseFrom and plugin.SessionReverseFrom, and report progress with plugin.ProgressFrom.

func ServeStdio

func ServeStdio(ctx context.Context, guest plugin.Endpoint) error

ServeStdio serves a standalone guest on stdin/stdout, including Go WASI commands. It owns and closes both streams. Send diagnostics to stderr only; stdout is reserved for the Ext protocol. Call once from the guest's main.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Connections must allow Close concurrently with Read/Write and unblock both. The client owns the supplied connection. One client belongs to one session.

One call is in flight at a time. While it is, the guest may send progress frames and reverse requests, and at any time after the handshake it may send session-scoped reverse requests; a reader goroutine, started with the first call, routes them so a blocked call never stops reverse calls from being served.

func NewClient

func NewClient(conn io.ReadWriteCloser) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Handshake

func (c *Client) Handshake(ctx context.Context) (plugin.Descriptor, error)

func (*Client) Invoke

func (c *Client) Invoke(ctx context.Context, r plugin.Request) (plugin.Response, error)

func (*Client) SetReverse

func (c *Client) SetReverse(h plugin.ReverseHost)

SetReverse registers the host that serves the guest's reverse calls. Open calls it before the handshake when the host configured Reverse.

type Func

type Func func(ctx context.Context, method string, payload json.RawMessage) (any, error)

Func handles one call for a guest that addresses operations by a single string, Contract.Name + "." + Operation. payload is the request payload (nil when absent). The result must be JSON-encodable.

type FuncOptions

type FuncOptions struct {
	// RedactErrors replaces the message of an ordinary error with a generic
	// one. By default the message reaches the host (as untrusted diagnostics).
	RedactErrors bool
	// MaxCallDuration is the guest-owned bound; zero uses plugin.DefaultTimeout.
	MaxCallDuration time.Duration
}

FuncOptions tunes ServeFunc and NewFuncGuest.

type Handler

type Handler = plugin.Handler

Handler performs consumer authorization and executes one domain call. It must honor ctx. Return a RemoteError to expose a deliberate public error; other errors are reduced to a stable generic response.

type Server

type Server struct {
	Descriptor      plugin.Descriptor
	Handler         Handler
	MaxCallDuration time.Duration
}

Server configures a domain endpoint. MaxCallDuration is a server-owned bound, independent of caller deadlines; zero defaults to plugin.DefaultTimeout.

func (Server) Serve

func (s Server) Serve(ctx context.Context, conn io.ReadWriteCloser) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL