websocket

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownID error = errors.New(unknownIDMessage)

ErrUnknownID can occur when the websocket session is expired or invalid

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	Event string      `json:"type"`
	Body  AttemptBody `json:"body"`
}

type AttemptBody

type AttemptBody struct {
	Path         string         `json:"cli_path"`
	EventID      string         `json:"event_id"`
	AttemptId    string         `json:"attempt_id"`
	ConnectionId string         `json:"webhook_id"`
	Request      AttemptRequest `json:"request"`
}

type AttemptRequest

type AttemptRequest struct {
	Method     string          `json:"method"`
	Timeout    int64           `json:"timeout"`
	DataString string          `json:"data_string"`
	Headers    json.RawMessage `json:"headers"`
}

type AttemptResponse

type AttemptResponse struct {
	Event string              `json:"event"`
	Body  AttemptResponseBody `json:"body"`
}

type AttemptResponseBody

type AttemptResponseBody struct {
	AttemptId string `json:"attempt_id"`
	CLIPath   string `json:"cli_path"`
	Status    int    `json:"status"`
	Data      string `json:"data"`
}

type Client

type Client struct {
	// URL the client connects to
	URL string

	CLIKey string

	TeamID string

	// ID sent by the client in the `Websocket-Id` header when connecting
	WebSocketID string

	NotifyExpired chan struct{}
	// contains filtered or unexported fields
}

Client is the client used to receive webhook requests from Hookdeck and send back webhook responses from the local endpoint to Hookdeck.

func NewClient

func NewClient(url string, webSocketID string, CLIKey string, teamID string, cfg *Config) *Client

NewClient returns a new Client.

func (*Client) Connected

func (c *Client) Connected() <-chan struct{}

Connected returns a channel that's closed when the client has finished establishing the websocket connection.

func (*Client) ConnectionLost

func (c *Client) ConnectionLost()

ConnectionLost sends NotifyExpired

func (*Client) Run

func (c *Client) Run(ctx context.Context)

Run starts listening for incoming webhook requests from Hookdeck.

func (*Client) SendMessage

func (c *Client) SendMessage(msg *OutgoingMessage)

SendMessage sends a message to Hookdeck through the websocket.

func (*Client) Stop

func (c *Client) Stop()

Stop stops listening for incoming webhook events.

type Config

type Config struct {
	ConnectAttemptWait time.Duration

	Dialer *ws.Dialer

	Log *log.Logger

	// Force use of unencrypted ws:// protocol instead of wss://
	NoWSS bool

	PingPeriod time.Duration

	PongWait time.Duration

	WriteWait time.Duration

	EventHandler EventHandler
}

Config contains the optional configuration parameters of a Client.

type ConnectionMessage

type ConnectionMessage struct {
	Event string                `json:"event"`
	Body  ConnectionMessageBody `json:"body"`
}

type ConnectionMessageBody

type ConnectionMessageBody struct {
	SourceId      string   `json:"source_id"`
	ConnectionIds []string `json:"webhook_ids"`
}

type ErrorAttemptBody

type ErrorAttemptBody struct {
	AttemptId string `json:"attempt_id"`
	Error     bool   `json:"error"`
}

type ErrorAttemptResponse

type ErrorAttemptResponse struct {
	Event string           `json:"event"`
	Body  ErrorAttemptBody `json:"body"`
}

type EventHandler

type EventHandler interface {
	ProcessEvent(IncomingMessage)
}

EventHandler handles an event.

type EventHandlerFunc

type EventHandlerFunc func(IncomingMessage)

EventHandlerFunc is an adapter to allow the use of ordinary functions as event handlers. If f is a function with the appropriate signature, EventHandlerFunc(f) is a EventHandler that calls f.

func (EventHandlerFunc) ProcessEvent

func (f EventHandlerFunc) ProcessEvent(msg IncomingMessage)

ProcessEvent calls f(msg).

type IncomingMessage

type IncomingMessage struct {
	*Attempt
}

IncomingMessage represents any incoming message sent by Hookdeck.

func (*IncomingMessage) UnmarshalJSON

func (m *IncomingMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes incoming messages sent by Hookdeck into the appropriate structure.

type OutgoingMessage

type OutgoingMessage struct {
	*ErrorAttemptResponse
	*AttemptResponse
	*ConnectionMessage
}

OutgoingMessage represents any outgoing message sent to Hookdeck.

func (OutgoingMessage) MarshalJSON

func (m OutgoingMessage) MarshalJSON() ([]byte, error)

MarshalJSON serializes outgoing messages sent to Hookdeck.

Jump to

Keyboard shortcuts

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