websocket

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

	// ID sent by the client in the `Websocket-Id` header when connecting
	WebSocketID string
	// contains filtered or unexported fields
}

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

func NewClient

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

NewClient returns a new Client.

func (*Client) Run

func (c *Client) Run()

Run starts listening for incoming webhook requests from Stripe.

func (*Client) SendMessage

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

SendMessage sends a message to Stripe 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

	// Interval at which the websocket client should reset the connection
	ReconnectInterval time.Duration

	WriteWait time.Duration

	WebhookEventHandler WebhookEventHandler
}

Config contains the optional configuration parameters of a Client.

type IncomingMessage

type IncomingMessage struct {
	*WebhookEvent
}

IncomingMessage represents any incoming message sent by Stripe.

func (*IncomingMessage) UnmarshalJSON

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

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

type OutgoingMessage

type OutgoingMessage struct {
	*WebhookResponse
}

OutgoingMessage represents any outgoing message sent to Stripe.

func NewWebhookResponse

func NewWebhookResponse(webhookID string, status int, body string, headers map[string]string) *OutgoingMessage

NewWebhookResponse returns a new webhookResponse message.

func (OutgoingMessage) MarshalJSON

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

MarshalJSON serializes outgoing messages sent to Stripe.

type WebhookEndpoint

type WebhookEndpoint struct {
	APIVersion *string `json:"api_version"`
}

WebhookEndpoint contains properties about the fake "endpoint" used to format the webhook event.

type WebhookEvent

type WebhookEvent struct {
	Endpoint     WebhookEndpoint   `json:"endpoint"`
	EventPayload string            `json:"event_payload"`
	HTTPHeaders  map[string]string `json:"http_headers"`
	Type         string            `json:"type"`
	WebhookID    string            `json:"webhook_id"`
}

WebhookEvent represents incoming webhook event messages sent by Stripe.

type WebhookEventHandler

type WebhookEventHandler interface {
	ProcessWebhookEvent(*WebhookEvent)
}

WebhookEventHandler handles a webhook event.

type WebhookEventHandlerFunc

type WebhookEventHandlerFunc func(*WebhookEvent)

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

func (WebhookEventHandlerFunc) ProcessWebhookEvent

func (f WebhookEventHandlerFunc) ProcessWebhookEvent(msg *WebhookEvent)

ProcessWebhookEvent calls f(msg).

type WebhookResponse

type WebhookResponse struct {
	Status      int               `json:"status"`
	HTTPHeaders map[string]string `json:"http_headers"`
	Body        string            `json:"body"`
	Type        string            `json:"type"`
	WebhookID   string            `json:"webhook_id"`
}

WebhookResponse represents outgoing webhook response messages sent to Stripe.

Jump to

Keyboard shortcuts

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