client

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	UserAgent      = "TRISA TRP Bridge Client/v1"
	Accept         = "application/json"
	AcceptLanguage = "en-US,en"
	AcceptEncode   = "gzip, deflate, br"
)

Variables

This section is empty.

Functions

func ContextWithRequestID

func ContextWithRequestID(parent context.Context, requestID string) context.Context

Adds a request identifer to the context which is sent with the request in the request-identifier header. (OpenVASP specific - should specify the request is about a specific transaction).

func ContextWithTracing

func ContextWithTracing(parent context.Context, tracingID string) context.Context

Adds a tracing ID to the context which is sent with the request in the X-Request-ID header. This is an per-request unique identifier that is used for tracing and observability, not for the protocol.

func NewRequest

func NewRequest(ctx context.Context, method string, ta *trp.Info, body io.Reader) (req *http.Request, err error)

Creates a new http request for use to a TRP server with the appropriate headers set. The headers are set by the info packet or by the defaults in the current version of this package if not set. The url the request is set to is extracted from the address info and can be either a travel rule address, an LNURL, or a standard URL.

For convenience the request identifier and a tracing id can be set in the context of the request. However, the request identifier in the address info will take priority. If there is no request identifier specified, then a UUID is generated.

If the body is not nil, this method sets the content type header to application/json as most requests require JSON payloads. If you need to send a different content type, ensure you reset the header after creating the request.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) (string, bool)

Extracts a request identifier from the context.

func TracingFromContext

func TracingFromContext(ctx context.Context) (string, bool)

Extracts a tracing ID from the context.

Types

type Client

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

func New

func New(opts ...ClientOption) (client *Client, err error)

New creates a TRP client that uses travel addresses to send TRP protocol requests. The client implements the TRP v3 API protocol as well as the Discoverability extension for querying the version, uptime, and extensions of a TRP server.

func (*Client) APIExtensions

func (c *Client) APIExtensions() []string

Returns the default API extensions used in requests.

func (*Client) APIVersion

func (c *Client) APIVersion() string

Returns the default API version used in requests.

func (*Client) Confirm

func (c *Client) Confirm(ctx context.Context, in *trp.Confirmation) (err error)

func (*Client) Do

func (c *Client) Do(req *http.Request, out interface{}) (reply *Response, err error)

Executes an http request, performs error checking, and deserializes the response data into the specified out interface. The out interface should implement either encoding.TextUnmarshaler in the case of text/plain responses or will be decoded using json in the case of application/json responses.

func (*Client) Extensions

func (c *Client) Extensions(ctx context.Context, address string) (out *discoverability.Extensions, err error)

func (*Client) Get

func (s *Client) Get(ctx context.Context, ta *trp.Info, out interface{}) (rep *Response, err error)

Executes an HTTP GET request expecting a JSON response (out) from the server. If out is nil or the status code is 204 then the body response will not be parsed.

func (*Client) Identity

func (c *Client) Identity(ctx context.Context, address string) (out *trp.Identity, err error)

func (*Client) Inquiry

func (c *Client) Inquiry(ctx context.Context, in *trp.Inquiry) (out *trp.Resolution, err error)

func (*Client) NewJSONRequest

func (c *Client) NewJSONRequest(ctx context.Context, method string, ta *trp.Info, data interface{}) (req *http.Request, err error)

Create a new JSON payload, marshaling the given data into a JSON object.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method string, ta *trp.Info, body io.Reader) (req *http.Request, err error)

Creates a new request with the default headers set and the client's API version and extensions. Use the NewJSONRequest and NewTextRequest methods handle specific data types and body encoding. See NewRequest for more information on the headers and context. This method also manages cookies from the cookiejar if needed for CSRF.

func (*Client) NewTextRequest

func (c *Client) NewTextRequest(ctx context.Context, method string, ta *trp.Info, data interface{}) (req *http.Request, err error)

Create a new text payload, wrapping the given text unmarshaler in a reader.

func (*Client) Post

func (s *Client) Post(ctx context.Context, ta *trp.Info, in, out interface{}) (rep *Response, err error)

Executes an HTTP POST request expecting a JSON payload (in) and accepts a JSON payload (out) from the server (though the response will be handled based on the content-type the server responds with). Both in and out can be nil to skip handling.

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, in *trp.Resolution) (err error)

func (*Client) Uptime

func (c *Client) Uptime(ctx context.Context, address string) (out discoverability.Uptime, err error)

func (*Client) Version

func (c *Client) Version(ctx context.Context, address string) (out *discoverability.Version, err error)

type ClientOption

type ClientOption func(c *Client) error

ClientOption allows us to configure the APIv1 client when it is created.

func WithAPIExtensions

func WithAPIExtensions(extensions ...string) ClientOption

Specify the default API extensions to use in requests (overwrites default extensions).

func WithAPIVersion

func WithAPIVersion(version string) ClientOption

Specify the default API version to use in requests.

func WithClient

func WithClient(client *http.Client) ClientOption

Specify the underlying HTTP client to use to make requests for complete control of how the HTTP transport is configured. This will overwrite any default configuration that the default client uses.

func WithMTLS

func WithMTLS(client *trust.Provider, pool trust.ProviderPool) ClientOption

WithMTLS allows the user to specify an mTLS provider and pool for the client.

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) ClientOption

Specify the mTLS or TLS configuration to use to connect to secure endpoints.

type Response

type Response struct {
	http.Response
	// contains filtered or unexported fields
}

func (*Response) Err

func (r *Response) Err() error

func (*Response) Info

func (r *Response) Info() *trp.Info

func (*Response) StatusError

func (r *Response) StatusError() (*trp.StatusError, bool)

Jump to

Keyboard shortcuts

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