bridge

package
v1.0.40 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BridgeConnectionInfo added in v1.0.40

type BridgeConnectionInfo struct {
	ExpiresAt    *time.Time `json:"expires_at"`
	WebsocketURL string     `json:"websocket_url"`
	StreamURL    string     `json:"stream_url"`
	ClientURL    string     `json:"client_url"`
	RepliesURL   string     `json:"replies_url"`
	RefreshURL   string     `json:"refresh_url"`
}

func (*BridgeConnectionInfo) IsExpired added in v1.0.40

func (b *BridgeConnectionInfo) IsExpired() bool

IsExpired returns true if the connection has expired

type Client

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

func New

func New(opts Options) *Client

New creates a new BridgeClient

func (*Client) ClientURL added in v1.0.40

func (c *Client) ClientURL() string

ClientURL returns the emphemeral client URL of the bridge connection

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) ConnectionInfo added in v1.0.40

func (c *Client) ConnectionInfo() BridgeConnectionInfo

ConnectionInfo returns the connection info for the bridge connection

func (*Client) ExpiresAt added in v1.0.40

func (c *Client) ExpiresAt() time.Time

ExpiresAt returns the expiration time of the connection

func (*Client) IsExpired added in v1.0.40

func (c *Client) IsExpired() bool

IsExpired returns true if the connection has expired

func (*Client) Refresh added in v1.0.40

func (c *Client) Refresh() error

Refresh refreshes the connection to the bridge server

func (*Client) Reply

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

Reply sends a reply to the incoming request

func (*Client) StreamURL added in v1.0.40

func (c *Client) StreamURL() string

StreamURL returns the stream URL of the bridge connection

func (*Client) WebsocketURL added in v1.0.40

func (c *Client) WebsocketURL() string

WebsocketURL returns the websocket 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)

	// OnDisconnect is called when the bridge client is disconnected from the bridge server
	OnDisconnect(client *Client)

	// 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)
	OnDisconnectFunc func(client *Client)
	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)

func (*HandlerCallback) OnData

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

func (*HandlerCallback) OnDisconnect added in v1.0.40

func (h *HandlerCallback) OnDisconnect(client *Client)

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
	// ConnectionInfo is the connection info for the bridge client (optional) which can be used to pre-populate the connection info
	ConnectionInfo *BridgeConnectionInfo
}

Jump to

Keyboard shortcuts

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