froda

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package froda provides a slink-compatible client for calling XRPC APIs.

Overview

Using an Old English name meaning "wise by experience", froda implements the calling interface used by the XRPC clients generated by slink.

Froda includes options for configuring connections to upstream hosts including both servers and proxies. Upstream addresses can be either TCP sockets (for typical HTTP networking) or Linux abstract sockets for communication with local hosts, such as sidecar proxies.

Froda configuration includes the following values, which can either be set using fields of the ClientOptions structure or as environment variables:

Environment Variable  | Header        | Purpose
----------------------|---------------|-----------------------------------------------------------
SLINK_HOST            | host          | The host to receive the request
SLINK_AUTHORIZATION   | authorization | The HTTP authorization header to be sent with the request
SLINK_ATPROTOPROXY    | atproto-proxy | An upstream service that should ultimately receive the request
SLINK_PROXYSESSION    | proxy-session | A session ID that corresponds to a user auth token
SLINK_USERDID         | user-did      | The DID of the user associated with the proxy session

The example below uses froda with an XRPC client generated by slink.

c := froda.NewClientWithOptions(froda.ClientOptions{
    Host: senderDidDocument.Service[0].ServiceEndpoint,
})
result, err := xrpc.ComATProtoServerCreateSession(cmd.Context(), c, &xrpc.ComATProtoServerCreateSession_Input{
    Identifier: senderDid,
    Password:   senderPassword,
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host          string
	Authorization string
	ATProtoProxy  string
	ProxySession  string
	UserDid       string
}

Client contains configurable settings for the client.

func NewClient

func NewClient() *Client

NewClient creates a new client that can be configured directly or with environment variables.

func NewClientWithOptions

func NewClientWithOptions(options ClientOptions) *Client

NewClientWithOptions creates a client using a user-specified set of options.

func (*Client) Do

func (c *Client) Do(
	ctx context.Context,
	kind slink.RequestType,
	contentType string,
	method string,
	params map[string]any,
	bodyvalue any,
	out any,
) error

Do performs an HTTP request using XRPC conventions.

func (*Client) SetSessionHeaders

func (c *Client) SetSessionHeaders(r *http.Request) *Client

SetSessionHeaders configures a client with headers sent with a request. This can be used to read caller identity sent by an authenticating proxy.

func (*Client) Subscribe

func (c *Client) Subscribe(
	ctx context.Context,
	method string,
	params map[string]any,
	callback func(b io.Reader) error,
) error

Subscribe performs a subscription using XRPC conventions.

type ClientOptions

type ClientOptions struct {
	Host          string
	Authorization string
	ATProtoProxy  string
	ProxySession  string
	UserDid       string
}

ClientOptions contains values that can be passed to NewClientWithOptions.

type XRPCError

type XRPCError struct {
	Code    int    `json:"code"`
	Title   string `json:"error"`
	Message string `json:"message"`
}

XRPCError represents errors returned from XRPC services.

func (*XRPCError) Error

func (e *XRPCError) Error() string

Error returns a string representation of an XRPCError.

Jump to

Keyboard shortcuts

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