cable

package
v0.0.0-...-03a7b74 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cable fala o protocolo do ActionCable (JSON sobre WebSocket) para acompanhar provisionamento, deploy e run ao vivo.

Index

Constants

This section is empty.

Variables

View Source
var ErrConnection = errors.New("WebSocket indisponível")

ErrConnection: o WebSocket não serve — quem chama cai para o polling.

Functions

func Identifier

func Identifier(channel string, params map[string]any) string

Identifier monta o identificador do canal, como o cliente JS do Rails.

Types

type Conn

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

Conn é uma conexão ActionCable. Toda goroutine que ela inicia (uma readLoop por WebSocket aberto) termina em Close() ou quando o contexto do Connect é cancelado: o contexto da conexão vive em c.ctx, independente do contexto de cada WaitFor, para que cancelar uma espera não derrube a conexão.

func Connect

func Connect(ctx context.Context, opts Options) (*Conn, error)

func (*Conn) Await

func (c *Conn) Await(ctx context.Context, id, channel string, until []string, onLine, onStatus func(string)) (string, error)

Await é a espera do WaitFor numa assinatura já feita (id devolvido pelo Subscribe): quem chama pode fazer algo entre assinar e esperar. onStatus recebe os status dessa assinatura que ainda não estão em until. As mesmas regras do WaitFor valem (uma espera por Conn).

func (*Conn) Close

func (c *Conn) Close()

Close encerra a conexão e espera as goroutines terminarem. É idempotente e pode ser chamado de qualquer goroutine, inclusive durante uma reconexão.

func (*Conn) Subscribe

func (c *Conn) Subscribe(ctx context.Context, channel string, params map[string]any) (string, error)

func (*Conn) WaitFor

func (c *Conn) WaitFor(ctx context.Context, channel string, params map[string]any, until []string, onLine func(string)) (string, error)

WaitFor assina o canal e espera um dos status de `until`. Linhas com `line` de qualquer assinatura vão para onLine (os logs de build, por exemplo). Recusa de outro canal é ignorada; só a recusa deste canal é erro. WaitFor não pode rodar em paralelo na mesma Conn: use uma Conn por acompanhamento, pois todas as esperas consumiriam o mesmo canal de eventos.

type Message

type Message struct {
	Status string `json:"status"`
	Line   string `json:"line"`
}

type Options

type Options struct {
	APIURL          string
	Token           string
	UserAgent       string
	WelcomeTimeout  time.Duration
	ReconnectDelays []time.Duration
	Debug           io.Writer // JATAI_DEBUG=1; o token só vai no cabeçalho, nunca num frame
}

Directories

Path Synopsis
Package cabletest é um servidor ActionCable falso para os testes.
Package cabletest é um servidor ActionCable falso para os testes.

Jump to

Keyboard shortcuts

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