Documentation
¶
Index ¶
- Variables
- type APIError
- func (e *APIError) Error() string
- func (e *APIError) IsBadRequest() bool
- func (e *APIError) IsConflict() bool
- func (e *APIError) IsNotFound() bool
- func (e *APIError) IsRequestEntityTooLarge() bool
- func (e *APIError) IsTransient() bool
- func (e *APIError) IsUnauthorized() bool
- func (e *APIError) Unwrap() error
- type APIErrorOption
- type ConfigurationError
- type NetworkError
- type Option
- type Publisher
- type PullJobOption
- type PullMessage
- type PullMessages
- type PullOption
- type SDKError
- type Subscriber
- func (s *Subscriber) Ack(ctx context.Context, ids []string) error
- func (s *Subscriber) Nack(ctx context.Context, ids []string) error
- func (s *Subscriber) Pull(ctx context.Context, opts ...PullOption) (PullMessages, error)
- func (s *Subscriber) PullJobCallback(ctx context.Context, callback func(ctx context.Context, messages PullMessages), ...) error
- func (s *Subscriber) PullJobChan(ctx context.Context, opts ...PullJobOption) (<-chan PullMessages, error)
- func (s *Subscriber) Wait()
Constants ¶
This section is empty.
Variables ¶
var ErrMissingCallback = NewConfigurationError("callback function is required", nil)
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int `json:"statusCode"`
Code string `json:"code"`
Msg string `json:"message"`
Err error `json:"-"`
}
APIError represents an error returned by the StackIT Pub/Sub API.
func NewAPIError ¶
func NewAPIError(statusCode int, body []byte, opts ...APIErrorOption) *APIError
NewAPIError constructs an APIError from the HTTP response details.
func (*APIError) IsBadRequest ¶
IsBadRequest returns true if the API returned a 400.
func (*APIError) IsConflict ¶
IsConflict returns true if the API returned a 409 (e.g., resource modified by another client).
func (*APIError) IsNotFound ¶
IsNotFound returns true if the API returned a 404 (e.g., Topic or Subscription doesn't exist).
func (*APIError) IsRequestEntityTooLarge ¶
IsRequestEntityTooLarge returns true if the API returned a 413.
func (*APIError) IsTransient ¶
func (*APIError) IsUnauthorized ¶
IsUnauthorized returns true if the API returned a 401.
type APIErrorOption ¶
type APIErrorOption func(*APIError)
APIErrorOption allows for customizing the APIError during initialization.
func WithUnderlyingError ¶
func WithUnderlyingError(err error) APIErrorOption
WithUnderlyingError attaches a root cause error to the APIError.
type ConfigurationError ¶
ConfigurationError indicates invalid client setup or credentials.
func NewConfigurationError ¶
func NewConfigurationError(msg string, err error) *ConfigurationError
func (*ConfigurationError) Error ¶
func (e *ConfigurationError) Error() string
func (*ConfigurationError) IsTransient ¶
func (e *ConfigurationError) IsTransient() bool
func (*ConfigurationError) Unwrap ¶
func (e *ConfigurationError) Unwrap() error
type NetworkError ¶
NetworkError indicates a failure to reach the StackIT API (e.g., DNS resolution, timeouts).
func NewNetworkError ¶
func NewNetworkError(msg string, err error) *NetworkError
func (*NetworkError) Error ¶
func (e *NetworkError) Error() string
func (*NetworkError) IsTransient ¶
func (e *NetworkError) IsTransient() bool
func (*NetworkError) Unwrap ¶
func (e *NetworkError) Unwrap() error
type Option ¶
type Option func(*clientConfig)
Option defines the functional option signature for configuring clients.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithHTTPRoundTripper ¶
func WithHTTPRoundTripper(rt http.RoundTripper) Option
WithHTTPRoundTripper sets a custom transport for the default HTTP client.
func WithLogger ¶
WithLogger sets the logger using a standard slog.Logger.
func WithLogrLogger ¶
WithLogrLogger sets the logger using a go-logr instance.
type Publisher ¶
func NewPublisher ¶
NewPublisher instantiates a new Publisher.
func (*Publisher) Publish ¶
Publish processes raw bytes, encodes them transparently using bytesToBase64, and transmits them out via the API client.
func (*Publisher) PublishStrings ¶
PublishStrings acts as a lightweight adapter converting string slice to byte slices, deferring all encoding safely to the core Publish method.
type PullJobOption ¶
type PullJobOption func(*pullJob)
func WithChannelBuffer ¶
func WithChannelBuffer(size int) PullJobOption
func WithErrorHandler ¶
func WithErrorHandler(handler func(err error) bool) PullJobOption
WithErrorHandler allows the user to handle non-transient background errors and dictate whether the subscriber loop should continue (return true) or halt (return false).
func WithInterval ¶
func WithInterval(interval time.Duration) PullJobOption
func WithPullLongPullDuration ¶
func WithPullLongPullDuration(milliseconds int32) PullJobOption
func WithPullMaxMessages ¶
func WithPullMaxMessages(maximum int32) PullJobOption
type PullMessage ¶
type PullMessage struct {
AckID string
Data []byte
CreateTime time.Time
DeliveryAttempts uint64
// contains filtered or unexported fields
}
func (*PullMessage) Bytes ¶
func (m *PullMessage) Bytes() []byte
Bytes exposes the underlying raw base64 data.
func (*PullMessage) DecodeString ¶
func (m *PullMessage) DecodeString() (string, error)
DecodeString reverses the transparent base64 encoding, returning the cleartext string.
type PullMessages ¶
type PullMessages []PullMessage
func (PullMessages) AckIDs ¶
func (m PullMessages) AckIDs() []string
AckIDs extracts all AckIDs cleanly from a slice of PullMessages.
func (PullMessages) DecodeStrings ¶
func (m PullMessages) DecodeStrings() ([]string, error)
DecodeStrings decodes an entire slice of messages. If any single message is corrupt, it returns the error immediately instead of swallowing it.
type PullOption ¶
type PullOption func(*pullOptions)
func WithLongPullDuration ¶
func WithLongPullDuration(milliseconds int32) PullOption
func WithMaxMessages ¶
func WithMaxMessages(maximum int32) PullOption
type Subscriber ¶
func NewSubscriber ¶
NewSubscriber instantiates a new Subscriber.
func (*Subscriber) Pull ¶
func (s *Subscriber) Pull(ctx context.Context, opts ...PullOption) (PullMessages, error)
func (*Subscriber) PullJobCallback ¶
func (s *Subscriber) PullJobCallback( ctx context.Context, callback func(ctx context.Context, messages PullMessages), opts ...PullJobOption, ) error
func (*Subscriber) PullJobChan ¶
func (s *Subscriber) PullJobChan(ctx context.Context, opts ...PullJobOption) (<-chan PullMessages, error)
func (*Subscriber) Wait ¶
func (s *Subscriber) Wait()