Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- type Config
- type DataElement
- type ErrorElement
- type EventAck
- type EventHandler
- type EventHandlerFunc
- type IElement
- type IncomingMessage
- type OutgoingMessage
- type RequestLogEvent
- type StateElement
- type Visitor
- type WarningElement
- type WebhookEndpoint
- type WebhookEvent
- type WebhookResponse
Constants ¶
const ( // Loading means the stream is being set up Loading state = iota // Reconnecting means the stream is reconnecting Reconnecting // Ready means we are ready to receive logs Ready // Done means log streaming is done Done )
Variables ¶
var ErrUnknownID = errors.New(unknownIDMessage)
ErrUnknownID can occur when the websocket session is expired or invalid
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 // Feature that the websocket is specified for WebSocketAuthorizedFeature string NotifyExpired chan struct{} // 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, websocketAuthorizedFeature string, cfg *Config) *Client
NewClient returns a new Client.
func (*Client) Close ¶ added in v1.7.1
Close executes a proper closure handshake then closes the connection list of close codes: https://datatracker.ietf.org/doc/html/rfc6455#section-7.4
func (*Client) Connected ¶ added in v0.7.6
func (c *Client) Connected() <-chan struct{}
Connected returns a channel that's closed when the client has finished establishing the websocket connection.
func (*Client) SendMessage ¶
func (c *Client) SendMessage(msg *OutgoingMessage)
SendMessage sends a message to Stripe through the websocket.
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 // Duration to wait before closing connection CloseDelayPeriod time.Duration WriteWait time.Duration EventHandler EventHandler }
Config contains the optional configuration parameters of a Client.
type DataElement ¶ added in v1.6.0
type DataElement struct { Data interface{} Marshaled string }
DataElement is the data received on the stream. It represents the main data model between communicated.
func (DataElement) Accept ¶ added in v1.6.0
func (le DataElement) Accept(v *Visitor) error
Accept is visitor pattern boilerplate
type ErrorElement ¶ added in v1.6.0
type ErrorElement struct {
Error error
}
ErrorElement is an error from the log tailer
func (ErrorElement) Accept ¶ added in v1.6.0
func (ee ErrorElement) Accept(v *Visitor) error
Accept is visitor pattern boilerplate
type EventAck ¶ added in v1.6.3
type EventAck struct { Type string `json:"type"` // always "event_ack" WebhookConversationID string `json:"webhook_conversation_id"` EventID string `json:"event_id"` // ID of the event }
EventAck represents outgoing Ack messages for events received by Stripe.
type EventHandler ¶ added in v0.2.4
type EventHandler interface {
ProcessEvent(IncomingMessage)
}
EventHandler handles an event.
type EventHandlerFunc ¶ added in v0.2.4
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 ¶ added in v0.2.4
func (f EventHandlerFunc) ProcessEvent(msg IncomingMessage)
ProcessEvent calls f(msg).
type IElement ¶ added in v1.6.0
IElement is an element that can be visited. This is visitor pattern boilerplate.
type IncomingMessage ¶
type IncomingMessage struct { *WebhookEvent *RequestLogEvent }
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 *EventAck }
OutgoingMessage represents any outgoing message sent to Stripe.
func NewEventAck ¶ added in v1.6.3
func NewEventAck(eventID, webhookConversationID string) *OutgoingMessage
NewEventAck returns a new EventAck message.
func NewWebhookResponse ¶
func NewWebhookResponse(webhookID, webhookConversationID, forwardURL 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 RequestLogEvent ¶ added in v0.2.4
type RequestLogEvent struct { EventPayload string `json:"event_payload"` // RequestLogID is the `resp_` id for the response event which is used as the request log event throughout the system. // This is different from the `EventPayload.RequestID` which is the `req_` id for the user's actual request, which they // can use to find their request in the dashboard. RequestLogID string `json:"request_log_id"` Type string `json:"type"` }
RequestLogEvent represents incoming request log event messages sent by Stripe.
type StateElement ¶ added in v1.6.0
type StateElement struct { State state Data []string }
StateElement is the current state of the stream: loading, ready, etc.
func (StateElement) Accept ¶ added in v1.6.0
func (se StateElement) Accept(v *Visitor) error
Accept is visitor pattern boilerplate
type Visitor ¶ added in v1.6.0
type Visitor struct { VisitError func(ErrorElement) error VisitData func(DataElement) error VisitStatus func(StateElement) error VisitWarning func(WarningElement) error }
Visitor should implement the handlers for each type of element
type WarningElement ¶ added in v1.6.0
type WarningElement struct {
Warning string
}
WarningElement is a warning from the log tailer
func (WarningElement) Accept ¶ added in v1.6.0
func (we WarningElement) Accept(v *Visitor) error
Accept is visitor pattern boilerplate
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"` WebhookConversationID string `json:"webhook_conversation_id"` WebhookID string `json:"webhook_id"` }
WebhookEvent represents incoming webhook event messages sent by Stripe.
type WebhookResponse ¶
type WebhookResponse struct { ForwardURL string `json:"forward_url"` Status int `json:"status"` HTTPHeaders map[string]string `json:"http_headers"` Body string `json:"body"` Type string `json:"type"` WebhookConversationID string `json:"webhook_conversation_id"` WebhookID string `json:"webhook_id"` }
WebhookResponse represents outgoing webhook response messages sent to Stripe.