core

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPages = errors.New("no pages remain")

ErrNoPages is a sentinel error used to signal that no pages remain.

This error should be used similar to io.EOF, such that it represents a non-actionable error.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int         `json:"-"`
	Header     http.Header `json:"-"`
	// contains filtered or unexported fields
}

APIError is a lightweight wrapper around the standard error interface that preserves the status code from the RPC, if any.

func NewAPIError

func NewAPIError(statusCode int, header http.Header, err error) *APIError

NewAPIError constructs a new API error.

func (*APIError) Error

func (a *APIError) Error() string

Error returns the API error's message.

func (*APIError) Unwrap

func (a *APIError) Unwrap() error

Unwrap returns the underlying error. This also makes the error compatible with errors.As and errors.Is.

type Auth0ClientEnvEntryOption

type Auth0ClientEnvEntryOption struct {
	Key   string
	Value string
}

Auth0ClientEnvEntryOption implements the RequestOption interface.

type BaseURLOption

type BaseURLOption struct {
	BaseURL string
}

BaseURLOption implements the RequestOption interface.

type BodyPropertiesOption

type BodyPropertiesOption struct {
	BodyProperties map[string]interface{}
}

BodyPropertiesOption implements the RequestOption interface.

type BufferStreamReader

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

BufferStreamReader reads data from a *bufio.Reader, which splits on newlines.

func (*BufferStreamReader) ReadFromStream

func (b *BufferStreamReader) ReadFromStream() ([]byte, error)

type ClientCredentialsAndAudienceOption

type ClientCredentialsAndAudienceOption struct {
	Ctx          *context.Context
	ClientID     string
	ClientSecret string
	Audience     string
	// contains filtered or unexported fields
}

type ClientCredentialsOption

type ClientCredentialsOption struct {
	Ctx          *context.Context
	ClientID     string
	ClientSecret string
	// contains filtered or unexported fields
}

type ClientCredentialsPrivateKeyJwtAndAudienceOption

type ClientCredentialsPrivateKeyJwtAndAudienceOption struct {
	Ctx        *context.Context
	ClientID   string
	PrivateKey string
	Algorithm  string
	Audience   string
	// contains filtered or unexported fields
}

type ClientCredentialsPrivateKeyJwtOption

type ClientCredentialsPrivateKeyJwtOption struct {
	Ctx        *context.Context
	ClientID   string
	PrivateKey string
	Algorithm  string
	// contains filtered or unexported fields
}

type CustomDomainHeaderOption

type CustomDomainHeaderOption struct {
	CustomDomainHeader string
}

CustomDomainHeaderOption implements the RequestOption interface.

type DebugOption

type DebugOption struct {
	Debug bool
}

DebugOption implements the RequestOption interface.

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient is an interface for a subset of the *http.Client.

type HTTPClientOption

type HTTPClientOption struct {
	HTTPClient HTTPClient
}

HTTPClientOption implements the RequestOption interface.

type HTTPHeaderOption

type HTTPHeaderOption struct {
	HTTPHeader http.Header
}

HTTPHeaderOption implements the RequestOption interface.

type InsecureOption

type InsecureOption struct{}

InsecureOption implements the RequestOption interface. This option is for testing purposes only and should not be used in production.

type MaxAttemptsOption

type MaxAttemptsOption struct {
	MaxAttempts uint
}

MaxAttemptsOption implements the RequestOption interface.

type MaxBufSizeOption

type MaxBufSizeOption struct {
	MaxBufSize int
}

MaxBufSizeOption implements the RequestOption interface.

type MaxStreamReconnectAttemptsOption

type MaxStreamReconnectAttemptsOption struct {
	MaxStreamReconnectAttempts uint
}

MaxStreamReconnectAttemptsOption implements the RequestOption interface.

type NoAuth0ClientInfoOption

type NoAuth0ClientInfoOption struct{}

NoAuth0ClientInfoOption implements the RequestOption interface.

type Page

type Page[Cursor comparable, T any, R any] struct {
	Results      []T
	Response     R
	RawResponse  PageResponse[Cursor, T, R]
	StatusCode   int
	Header       http.Header
	NextPageFunc func(context.Context) (*Page[Cursor, T, R], error)
}

Page represents a single page of results.

func (*Page[Cursor, T, R]) GetNextPage

func (p *Page[Cursor, T, R]) GetNextPage(ctx context.Context) (*Page[Cursor, T, R], error)

GetNextPage fetches the next page, if any. If no pages remain, the ErrNoPages error is returned.

func (*Page[Cursor, T, R]) Iterator

func (p *Page[Cursor, T, R]) Iterator() *PageIterator[Cursor, T, R]

Iterator returns an iterator that starts at the current page.

type PageIterator

type PageIterator[Cursor comparable, T any, R any] struct {
	// contains filtered or unexported fields
}

PageIterator is an auto-iterator for paginated endpoints.

func (*PageIterator[Cursor, T, R]) Current

func (p *PageIterator[Cursor, T, R]) Current() T

Current returns the current element.

func (*PageIterator[Cursor, T, R]) Err

func (p *PageIterator[Cursor, T, R]) Err() error

Err returns a non-nil error if the iterator encountered an error.

func (*PageIterator[Cursor, T, R]) Next

func (p *PageIterator[Cursor, T, R]) Next(ctx context.Context) bool

Next returns true if the given iterator has more results, fetching the next page as needed.

type PageRequest

type PageRequest[Cursor comparable] struct {
	Cursor Cursor

	// Holds the value of the response type (populated by the *Caller).
	Response any
}

PageRequest represents the information required to identify a single page.

type PageResponse

type PageResponse[Cursor comparable, T any, R any] struct {
	Results  []T
	Response R
	Next     Cursor
	Done     bool
}

PageResponse represents the information associated with a single page.

Type parameters:

  • Cursor: the type used for pagination (e.g., string cursor or integer offset)
  • T: the type of individual items in the page
  • R: the response type returned by the paginated endpoint

type QueryParametersOption

type QueryParametersOption struct {
	QueryParameters url.Values
}

QueryParametersOption implements the RequestOption interface.

type ReconnectFunc

type ReconnectFunc func(ctx context.Context, lastEventID string) (*http.Response, error)

ReconnectFunc is invoked when the underlying SSE response body reaches EOF before the configured terminator is observed and reconnection is enabled. It must return a fresh *http.Response with the same SSE semantics.

type RequestOption

type RequestOption interface {
	// contains filtered or unexported methods
}

RequestOption adapts the behavior of the client or an individual request.

type RequestOptions

type RequestOptions struct {
	BaseURL                    string
	HTTPClient                 HTTPClient
	HTTPHeader                 http.Header
	BodyProperties             map[string]interface{}
	QueryParameters            url.Values
	MaxAttempts                uint
	MaxBufSize                 int
	MaxStreamReconnectAttempts uint
	DisableStreamReconnection  bool
	DisableRetries             bool

	Ctx         context.Context
	Token       string
	TokenSource oauth2.TokenSource
	Insecure    bool // For testing purposes only - allows HTTP instead of HTTPS

	// Auth0ClientEnv holds custom environment entries for the Auth0-Client header
	Auth0ClientEnv map[string]string

	// NoAuth0ClientInfo when true, prevents sending the "Auth0-Client" header
	NoAuth0ClientInfo bool

	// CustomDomainHeader is the custom domain to be sent in the "Auth0-Custom-Domain" header
	// for whitelisted API endpoints
	CustomDomainHeader string
}

RequestOptions defines all of the possible request options.

This type is primarily used by the generated code and is not meant to be used directly; use the option package instead.

func NewRequestOptions

func NewRequestOptions(opts ...RequestOption) *RequestOptions

NewRequestOptions returns a new *RequestOptions value.

This function is primarily used by the generated code and is not meant to be used directly; use RequestOption instead.

func (*RequestOptions) ToHeader

func (r *RequestOptions) ToHeader() http.Header

ToHeader maps the configured request options into a http.Header used for the request(s).

type Response

type Response[T any] struct {
	StatusCode int
	Header     http.Header
	Body       T
}

Response is an HTTP response from an HTTP client.

type ScannerStreamReader

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

ScannerStreamReader reads data from a *bufio.Scanner, which allows for configurable delimiters.

func (*ScannerStreamReader) ReadFromStream

func (s *ScannerStreamReader) ReadFromStream() ([]byte, error)

type SseEvent

type SseEvent struct {
	SseEventMeta
	Data []byte
	// contains filtered or unexported fields
}

func (*SseEvent) String

func (event *SseEvent) String() string

type SseEventMeta

type SseEventMeta struct {
	ID    string
	Event string
	// Retry is the reconnection time in milliseconds.
	// Zero if not set or if the value was not a valid integer.
	Retry int
}

SseEventMeta holds SSE metadata fields shared by StreamEvent and StreamEventRaw.

type SseStreamReader

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

func (*SseStreamReader) LastEventID

func (s *SseStreamReader) LastEventID() string

LastEventID returns the most recently received event ID.

func (*SseStreamReader) LastRetryMs

func (s *SseStreamReader) LastRetryMs() int

LastRetryMs returns the most recently parsed `retry:` directive value in milliseconds, or 0 if the stream has not advertised one.

func (*SseStreamReader) ReadEvent

func (s *SseStreamReader) ReadEvent() (*SseEvent, error)

ReadEvent reads the next SSE event with full metadata, skipping comment-only events.

func (*SseStreamReader) ReadFromStream

func (s *SseStreamReader) ReadFromStream() ([]byte, error)

func (*SseStreamReader) TerminatorSeen

func (s *SseStreamReader) TerminatorSeen() bool

TerminatorSeen reports whether the configured terminator was observed by this reader.

type Stream

type Stream[T any] struct {
	// contains filtered or unexported fields
}

Stream represents a stream of messages sent from a server.

Stream is not safe for concurrent use by multiple goroutines. Cancel the context passed to NewStream to tear the stream down.

func NewStream

func NewStream[T any](ctx context.Context, response *http.Response, opts ...StreamOption) *Stream[T]

NewStream constructs a new Stream from the given *http.Response.

func (*Stream[T]) Close

func (s *Stream[T]) Close() error

Close closes the Stream.

func (*Stream[T]) LastEventID

func (s *Stream[T]) LastEventID() string

LastEventID returns the most recently received event ID. Per the SSE spec, the last event ID persists across events (until explicitly reset by an `id:` line with an empty value) and should be sent as the Last-Event-ID header when reconnecting.

When WithReconnect is configured, the value persists across reconnects: each new reader starts with no ID, so callers see the pre-reconnect snapshot until the resumed stream emits an `id:` field of its own.

func (*Stream[T]) LastRetryMs

func (s *Stream[T]) LastRetryMs() int

LastRetryMs returns the most recently advertised SSE `retry:` reconnection time in milliseconds, or 0 if the server has not sent one. Per the SSE spec the value is sticky: a `retry:` directive — even one sent in its own frame with no `data:` — remains in effect for subsequent events until the server sends a new one, so the per-event StreamEvent.Retry can be 0 while this returns the advertised interval. The runtime already honors this value when gating reconnect backoff; this accessor exposes it so callers can observe it, mirroring LastEventID.

When WithReconnect is configured, the value persists across reconnects: each new reader starts with no retry directive, so callers see the pre-reconnect snapshot until the resumed stream advertises a `retry:` of its own.

func (*Stream[T]) Recv

func (s *Stream[T]) Recv() (T, error)

Recv reads a message from the stream, returning io.EOF when all the messages have been read.

func (*Stream[T]) RecvEvent

func (s *Stream[T]) RecvEvent() (StreamEvent[T], error)

RecvEvent reads the next event from the stream, including SSE metadata (id, event type, retry). Returns io.EOF when all events have been read.

This is only meaningful for SSE streams. For non-SSE streams, the metadata fields will always be zero-valued.

func (*Stream[T]) RecvEventRaw

func (s *Stream[T]) RecvEventRaw() (StreamEventRaw, error)

RecvEventRaw reads the next event from the stream without JSON unmarshaling, including SSE metadata. Returns io.EOF when all events have been read.

func (*Stream[T]) RecvRaw

func (s *Stream[T]) RecvRaw() ([]byte, error)

RecvRaw reads a raw message from the stream without JSON unmarshaling, returning io.EOF when all the messages have been read.

type StreamEvent

type StreamEvent[T any] struct {
	SseEventMeta
	Data T
}

StreamEvent contains the parsed data and SSE metadata for a single event.

type StreamEventRaw

type StreamEventRaw struct {
	SseEventMeta
	Data []byte
}

StreamEventRaw contains the raw bytes and SSE metadata for a single event.

type StreamFormat

type StreamFormat string
const (
	StreamFormatSSE   StreamFormat = "sse"
	StreamFormatEmpty StreamFormat = ""
)

type StreamOption

type StreamOption func(*streamOptions)

StreamOption adapts the behavior of the Stream.

func WithDelimiter

func WithDelimiter(delimiter string) StreamOption

WithDelimiter overrides the delimiter for the Stream.

By default, the Stream is newline-delimited.

func WithEventDiscriminator

func WithEventDiscriminator(field string) StreamOption

WithEventDiscriminator configures the SSE stream reader to inject the SSE event field value as a JSON discriminator into the data payload. This is used for protocol-level discrimination where the union discriminant comes from the SSE event: field rather than from within the JSON data.

func WithFormat

func WithFormat(format StreamFormat) StreamOption

WithFormat overrides the isSSE flag for the Stream.

By default, the Stream is not SSE.

func WithMaxBufSize

func WithMaxBufSize(size int) StreamOption

WithMaxBufSize overrides the maximum buffer size for the Stream.

This controls the maximum size of a single message (in bytes) that the stream can process. By default, this is set to 1MB. If your streaming responses contain messages larger than the default, increase this value.

func WithPrefix

func WithPrefix(prefix string) StreamOption

WithPrefix overrides the prefix for the Stream.

By default, the Stream doesn't have a prefix.

func WithReconnect

func WithReconnect(fn ReconnectFunc, maxAttempts uint) StreamOption

WithReconnect enables transparent mid-stream reconnection for SSE streams. fn is invoked on premature io.EOF (before the configured terminator) with the most recent SSE event ID; the returned *http.Response continues the iteration. maxAttempts caps reconnects; 0 falls back to the package default. No effect on non-SSE streams.

func WithTerminator

func WithTerminator(terminator string) StreamOption

WithTerminator overrides the terminator for the Stream.

By default, the Stream terminates on EOF.

type TokenOption

type TokenOption struct {
	Token string
}

TokenOption implements the RequestOption interface.

type TokenSourceOption

type TokenSourceOption struct {
	TokenSource oauth2.TokenSource
}

TokenSourceOption implements the RequestOption interface.

type UserAgentOption

type UserAgentOption struct {
	UserAgent string
}

UserAgentOption implements the RequestOption interface.

type WithoutRetriesOption

type WithoutRetriesOption struct{}

WithoutRetriesOption implements the RequestOption interface.

type WithoutStreamReconnectionOption

type WithoutStreamReconnectionOption struct{}

WithoutStreamReconnectionOption implements the RequestOption interface.

Jump to

Keyboard shortcuts

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