Help us shape the future of Go! Take the 2026 Go Developer Survey

pubsub

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) Error

func (e *APIError) Error() string

func (*APIError) IsBadRequest

func (e *APIError) IsBadRequest() bool

IsBadRequest returns true if the API returned a 400.

func (*APIError) IsConflict

func (e *APIError) IsConflict() bool

IsConflict returns true if the API returned a 409 (e.g., resource modified by another client).

func (*APIError) IsNotFound

func (e *APIError) IsNotFound() bool

IsNotFound returns true if the API returned a 404 (e.g., Topic or Subscription doesn't exist).

func (*APIError) IsRequestEntityTooLarge

func (e *APIError) IsRequestEntityTooLarge() bool

IsRequestEntityTooLarge returns true if the API returned a 413.

func (*APIError) IsTransient

func (e *APIError) IsTransient() bool

func (*APIError) IsUnauthorized

func (e *APIError) IsUnauthorized() bool

IsUnauthorized returns true if the API returned a 401.

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

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

type ConfigurationError struct {
	Msg string
	Err error
}

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

type NetworkError struct {
	Msg string
	Err error
}

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

func WithHTTPClient(client *http.Client) Option

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 WithHost

func WithHost(host string) Option

WithHost sets a custom host for the data plane API.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger using a standard slog.Logger.

func WithLogrLogger

func WithLogrLogger(logger logr.Logger) Option

WithLogrLogger sets the logger using a go-logr instance.

type Publisher

type Publisher struct {
	TopicID uuid.UUID
	// contains filtered or unexported fields
}

func NewPublisher

func NewPublisher(topicID uuid.UUID, opts ...Option) *Publisher

NewPublisher instantiates a new Publisher.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, messages [][]byte) error

Publish processes raw bytes, encodes them transparently using bytesToBase64, and transmits them out via the API client.

func (*Publisher) PublishStrings

func (p *Publisher) PublishStrings(ctx context.Context, messages ...string) error

PublishStrings acts as a lightweight adapter converting string slice to byte slices, deferring all encoding safely to the core Publish method.

func (*Publisher) Purge

func (p *Publisher) Purge(ctx context.Context) error

Purge removes all messages currently stored in the topic.

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) Ack

func (m *PullMessage) Ack(ctx context.Context) error

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.

func (*PullMessage) Nack

func (m *PullMessage) Nack(ctx context.Context) error

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 SDKError

type SDKError interface {
	// Error returns a string representation of the error.
	Error() string
	// Unwrap returns the underlying cause of the error, if any.
	Unwrap() error
	// IsTransient returns true if the error is temporary and can be retried
	IsTransient() bool
}

type Subscriber

type Subscriber struct {
	SubscriptionID uuid.UUID
	// contains filtered or unexported fields
}

func NewSubscriber

func NewSubscriber(topicID uuid.UUID, subscriptionID uuid.UUID, opts ...Option) *Subscriber

NewSubscriber instantiates a new Subscriber.

func (*Subscriber) Ack

func (s *Subscriber) Ack(ctx context.Context, ids []string) error

func (*Subscriber) Nack

func (s *Subscriber) Nack(ctx context.Context, ids []string) error

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()

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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