channels

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package channels provides operations for managing channels in the CREC platform.

Channels are logical groupings that organize watchers, events, and operations. Think of channels as "workspaces" or "projects" that group related blockchain monitoring and transaction activities together.

Usage

Channels are typically accessed through the main SDK client:

client, _ := crec.NewClient(baseURL, apiKey)

channel, err := client.Channels.Create(ctx, CreateInput{
    Name: "production-settlements",
})

For advanced use cases, create the client directly:

channelsClient, err := channels.NewClient(&channels.Options{
    APIClient: apiClient,
    Logger:    &logger,
})

Creating Channels

Channel names must be unique within your account:

channel, err := client.Channels.Create(ctx, CreateInput{
    Name: "production-dvp-settlements",
})
fmt.Printf("Created: %s (ID: %s)\n", channel.Name, channel.ChannelId)

Listing Channels

Use Client.List with optional filtering:

// List all channels
channels, hasMore, err := client.Channels.List(ctx, ListInput{})

// Filter by name
filterName := "production"
channels, hasMore, err := client.Channels.List(ctx, ListInput{
    Name:  &filterName,
    Limit: ptr(10),
})

// Filter by status
statuses := []apiClient.ChannelStatus{apiClient.ChannelStatusActive}
channels, hasMore, err = client.Channels.List(ctx, ListInput{
    Status: &statuses,
})

Getting and Archiving

Retrieve a specific channel by ID:

channel, err := client.Channels.Get(ctx, channelID)

Archive a channel (sets status to "archived"):

channel, err := client.Channels.Archive(ctx, channelID)

Integration with Other Clients

Channels scope watchers, events, and operations:

// Create a channel
channel, _ := client.Channels.Create(ctx, CreateInput{Name: "my-channel"})

// Create watchers in the channel
watcher, _ := client.Watchers.CreateWithService(ctx, channel.ChannelId, ...)

// Poll events from the channel
events, _, _ := client.Events.Poll(ctx, channel.ChannelId, nil)

// Execute operations in the channel
result, _ := client.Transact.ExecuteOperation(ctx, channel.ChannelId, ...)

Error Handling

All errors can be inspected with errors.Is:

if errors.Is(err, ErrChannelNotFound) {
    // Handle 404
}
if errors.Is(err, ErrChannelNameRequired) {
    // Handle validation error
}

Index

Constants

View Source
const (
	MaxChannelNameLength = 255
)

Variables

View Source
var (
	// ErrChannelNotFound is returned when a channel is not found (404 response)
	ErrChannelNotFound = errors.New("channel not found")

	// Client initialization errors
	ErrOptionsRequired   = errors.New("options is required")
	ErrAPIClientRequired = errors.New("APIClient is required")

	// Validation errors
	ErrChannelNameRequired = errors.New("channel name is required")
	ErrChannelNameTooLong  = errors.New("channel name too long")

	// API operation errors
	ErrCreateChannel  = errors.New("failed to create channel")
	ErrGetChannel     = errors.New("failed to get channel")
	ErrListChannels   = errors.New("failed to list channels")
	ErrUpdateChannel  = errors.New("failed to update channel")
	ErrArchiveChannel = errors.New("failed to archive channel")

	// Response errors
	ErrUnexpectedStatusCode = errors.New("unexpected status code")
	ErrNilResponseBody      = errors.New("unexpected nil response body")
)

Sentinel errors

Functions

This section is empty.

Types

type Client

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

Client provides operations for managing CREC channels. Channels are logical groupings that allow you to organize your watchers, events, and operations.

func NewClient

func NewClient(opts *Options) (*Client, error)

NewClient creates a new CREC Channels client with the provided options. Returns a pointer to the Client and an error if any issues occur during initialization.

  • opts: Options for configuring the CREC Channels client, see Options for details.

func (*Client) Archive

func (c *Client) Archive(ctx context.Context, channelID uuid.UUID) (*apiClient.Channel, error)

Archive archives a channel by transitioning it to archived status via PATCH. Archiving is synchronous and returns the channel in "archived" status. A channel cannot be archived if it has active watchers.

Parameters:

  • ctx: The context for the request.
  • channelID: The UUID of the channel to archive.

Returns the archived channel or an error if the operation fails or the channel is not found.

func (*Client) Create

func (c *Client) Create(ctx context.Context, input CreateInput) (*apiClient.Channel, error)

Create creates a new channel in the CREC backend.

Parameters:

  • ctx: The context for the request.
  • input: The channel creation parameters.

Returns the created channel or an error if the operation fails.

func (*Client) Get

func (c *Client) Get(ctx context.Context, channelID uuid.UUID) (*apiClient.Channel, error)

Get retrieves a specific channel by its ID.

Parameters:

  • ctx: The context for the request.
  • channelID: The UUID of the channel to retrieve.

Returns the channel or an error if the operation fails or the channel is not found.

func (*Client) List

func (c *Client) List(ctx context.Context, input ListInput) ([]apiClient.Channel, bool, error)

List retrieves a list of channels.

Parameters:

  • ctx: The context for the request.
  • input: The list parameters including filters and pagination.

Returns a list of channels and a boolean indicating if there are more results.

func (*Client) Update

func (c *Client) Update(ctx context.Context, channelID uuid.UUID, input UpdateInput) (*apiClient.Channel, error)

Update updates a channel's information.

Parameters:

  • ctx: The context for the request.
  • channelID: The UUID of the channel to update.
  • input: The channel update parameters.

Returns the updated channel or an error if the operation fails or the channel is not found.

type CreateInput

type CreateInput struct {
	Name        string
	Description *string
}

CreateInput defines the input parameters for creating a new channel.

  • Name: The name of the channel. Must be unique.
  • Description: Optional description of the channel.

type ListInput

type ListInput struct {
	Name   *string
	Status *[]apiClient.ChannelStatus
	Limit  *int
	Offset *int64
}

ListInput defines the input parameters for listing channels.

  • Name: Optional filter to search channels by name.
  • Status: Optional filter to search channels by status (e.g., active, archived). Archived channels are excluded by default.
  • Limit: Maximum number of channels to return (1-50, default: 20).
  • Offset: Number of channels to skip for pagination (default: 0).

type Options

type Options struct {
	Logger    *slog.Logger
	APIClient *apiClient.ClientWithResponses
}

Options defines the options for creating a new CREC Channels client.

  • Logger: Optional logger instance.
  • APIClient: The CREC API client instance.

type UpdateInput

type UpdateInput struct {
	Name        string
	Description *string
}

UpdateInput defines the input parameters for updating a channel.

  • Name: The new name for the channel.
  • Description: Optional new description for the channel.

Jump to

Keyboard shortcuts

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