Documentation
¶
Index ¶
- Variables
- type APIError
- type Auth0ClientEnvEntryOption
- type BaseURLOption
- type BodyPropertiesOption
- type BufferStreamReader
- type ClientCredentialsAndAudienceOption
- type ClientCredentialsOption
- type ClientCredentialsPrivateKeyJwtAndAudienceOption
- type ClientCredentialsPrivateKeyJwtOption
- type CustomDomainHeaderOption
- type DebugOption
- type HTTPClient
- type HTTPClientOption
- type HTTPHeaderOption
- type InsecureOption
- type MaxAttemptsOption
- type MaxBufSizeOption
- type MaxStreamReconnectAttemptsOption
- type NoAuth0ClientInfoOption
- type Page
- type PageIterator
- type PageRequest
- type PageResponse
- type QueryParametersOption
- type ReconnectFunc
- type RequestOption
- type RequestOptions
- type Response
- type ScannerStreamReader
- type SseEvent
- type SseEventMeta
- type SseStreamReader
- type Stream
- func (s *Stream[T]) Close() error
- func (s *Stream[T]) LastEventID() string
- func (s *Stream[T]) LastRetryMs() int
- func (s *Stream[T]) Recv() (T, error)
- func (s *Stream[T]) RecvEvent() (StreamEvent[T], error)
- func (s *Stream[T]) RecvEventRaw() (StreamEventRaw, error)
- func (s *Stream[T]) RecvRaw() ([]byte, error)
- type StreamEvent
- type StreamEventRaw
- type StreamFormat
- type StreamOption
- func WithDelimiter(delimiter string) StreamOption
- func WithEventDiscriminator(field string) StreamOption
- func WithFormat(format StreamFormat) StreamOption
- func WithMaxBufSize(size int) StreamOption
- func WithPrefix(prefix string) StreamOption
- func WithReconnect(fn ReconnectFunc, maxAttempts uint) StreamOption
- func WithTerminator(terminator string) StreamOption
- type TokenOption
- type TokenSourceOption
- type UserAgentOption
- type WithoutRetriesOption
- type WithoutStreamReconnectionOption
Constants ¶
This section is empty.
Variables ¶
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 ¶
NewAPIError constructs a new API error.
type Auth0ClientEnvEntryOption ¶
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 ¶ added in v2.10.0
type BufferStreamReader struct {
// contains filtered or unexported fields
}
BufferStreamReader reads data from a *bufio.Reader, which splits on newlines.
func (*BufferStreamReader) ReadFromStream ¶ added in v2.10.0
func (b *BufferStreamReader) ReadFromStream() ([]byte, error)
type ClientCredentialsOption ¶
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 ¶
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 ¶
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 ¶ added in v2.10.0
type MaxBufSizeOption struct {
MaxBufSize int
}
MaxBufSizeOption implements the RequestOption interface.
type MaxStreamReconnectAttemptsOption ¶ added in v2.12.0
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 ¶
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.
type PageRequest ¶ added in v2.3.0
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 ¶ added in v2.3.0
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 ¶
QueryParametersOption implements the RequestOption interface.
type ReconnectFunc ¶ added in v2.12.0
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 ScannerStreamReader ¶ added in v2.10.0
type ScannerStreamReader struct {
// contains filtered or unexported fields
}
ScannerStreamReader reads data from a *bufio.Scanner, which allows for configurable delimiters.
func (*ScannerStreamReader) ReadFromStream ¶ added in v2.10.0
func (s *ScannerStreamReader) ReadFromStream() ([]byte, error)
type SseEvent ¶ added in v2.10.0
type SseEvent struct {
SseEventMeta
Data []byte
// contains filtered or unexported fields
}
type SseEventMeta ¶ added in v2.10.0
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 ¶ added in v2.10.0
type SseStreamReader struct {
// contains filtered or unexported fields
}
func (*SseStreamReader) LastEventID ¶ added in v2.10.0
func (s *SseStreamReader) LastEventID() string
LastEventID returns the most recently received event ID.
func (*SseStreamReader) LastRetryMs ¶ added in v2.12.0
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 ¶ added in v2.10.0
func (s *SseStreamReader) ReadEvent() (*SseEvent, error)
ReadEvent reads the next SSE event with full metadata, skipping comment-only events.
func (*SseStreamReader) ReadFromStream ¶ added in v2.10.0
func (s *SseStreamReader) ReadFromStream() ([]byte, error)
func (*SseStreamReader) TerminatorSeen ¶ added in v2.12.0
func (s *SseStreamReader) TerminatorSeen() bool
TerminatorSeen reports whether the configured terminator was observed by this reader.
type Stream ¶ added in v2.10.0
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 ¶ added in v2.10.0
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]) LastEventID ¶ added in v2.10.0
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 ¶ added in v2.12.0
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 ¶ added in v2.10.0
Recv reads a message from the stream, returning io.EOF when all the messages have been read.
func (*Stream[T]) RecvEvent ¶ added in v2.10.0
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 ¶ added in v2.10.0
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.
type StreamEvent ¶ added in v2.10.0
type StreamEvent[T any] struct { SseEventMeta Data T }
StreamEvent contains the parsed data and SSE metadata for a single event.
type StreamEventRaw ¶ added in v2.10.0
type StreamEventRaw struct {
SseEventMeta
Data []byte
}
StreamEventRaw contains the raw bytes and SSE metadata for a single event.
type StreamFormat ¶ added in v2.10.0
type StreamFormat string
const ( StreamFormatSSE StreamFormat = "sse" StreamFormatEmpty StreamFormat = "" )
type StreamOption ¶ added in v2.10.0
type StreamOption func(*streamOptions)
StreamOption adapts the behavior of the Stream.
func WithDelimiter ¶ added in v2.10.0
func WithDelimiter(delimiter string) StreamOption
WithDelimiter overrides the delimiter for the Stream.
By default, the Stream is newline-delimited.
func WithEventDiscriminator ¶ added in v2.10.0
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 ¶ added in v2.10.0
func WithFormat(format StreamFormat) StreamOption
WithFormat overrides the isSSE flag for the Stream.
By default, the Stream is not SSE.
func WithMaxBufSize ¶ added in v2.10.0
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 ¶ added in v2.10.0
func WithPrefix(prefix string) StreamOption
WithPrefix overrides the prefix for the Stream.
By default, the Stream doesn't have a prefix.
func WithReconnect ¶ added in v2.12.0
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 ¶ added in v2.10.0
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 ¶ added in v2.6.0
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 ¶ added in v2.12.0
type WithoutRetriesOption struct{}
WithoutRetriesOption implements the RequestOption interface.
type WithoutStreamReconnectionOption ¶ added in v2.12.0
type WithoutStreamReconnectionOption struct{}
WithoutStreamReconnectionOption implements the RequestOption interface.