bridge

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(opts Options) *Client

New creates a new BridgeClient

func (*Client) Close

func (c *Client) Close()

Close closes the bridge client and disconnects from the bridge server

func (*Client) Connect

func (c *Client) Connect() error

Connect connects to the bridge and returns a new Client

func (*Client) Reply

func (c *Client) Reply(requestId string, status int, headers map[string]string, reader io.Reader) error

Reply sends a reply to the incoming request

func (*Client) URL

func (c *Client) URL() string

URL returns the ephemeral URL of the bridge connection

type Handler

type Handler interface {
	// OnConnect is called when the bridge client is connected to the bridge server
	OnConnect(client *Client, url string)

	// OnHeader is called when a header is received from the bridge. this will only be called once before any data is sent.
	OnHeader(client *Client, id string, headers map[string]string)

	// OnData is called when a data is received from the bridge. this will be called multiple times if the data is large.
	OnData(client *Client, id string, data []byte)

	// OnClose is called when the bridge request is completed and no more data will be sent
	OnClose(client *Client, id string)

	// OnError is called when an error occurs at any point in the bridge client
	OnError(client *Client, err error)
}

Handler is an interface that defines the callback methods for a bridge handler to implement

type HandlerCallback

type HandlerCallback struct {
	OnConnectFunc func(client *Client, url string)
	OnHeaderFunc  func(client *Client, id string, headers map[string]string)
	OnDataFunc    func(client *Client, id string, data []byte)
	OnCloseFunc   func(client *Client, id string)
	OnErrorFunc   func(client *Client, err error)
}

HandlerCallback is a struct that implements the BridgeHandler interface

func (*HandlerCallback) OnClose

func (h *HandlerCallback) OnClose(client *Client, id string)

func (*HandlerCallback) OnConnect

func (h *HandlerCallback) OnConnect(client *Client, url string)

func (*HandlerCallback) OnData

func (h *HandlerCallback) OnData(client *Client, id string, data []byte)

func (*HandlerCallback) OnError

func (h *HandlerCallback) OnError(client *Client, err error)

func (*HandlerCallback) OnHeader

func (h *HandlerCallback) OnHeader(client *Client, id string, headers map[string]string)

type Options

type Options struct {
	// Context is the context for the bridge client (optional)
	Context context.Context
	// Logger is the logger for the bridge client (optional)
	Logger logger.Logger
	// URL is the URL of the bridge (optional)
	URL string
	// APIKey is the API key for the bridge (optional, will use AGENTUITY_API_KEY environment variable if not set)
	APIKey string
	// Handler is the handler for the bridge client (required)
	Handler Handler
}

Jump to

Keyboard shortcuts

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