proxy

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: Apache-2.0 Imports: 14 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DeviceName is the name of the device sent to Stripe to help identify the device
	DeviceName string

	// Key is the API key used to authenticate with Stripe
	Key string

	// EndpointsMap is a mapping of local webhook endpoint urls to the events they consume
	EndpointRoutes []EndpointRoute

	APIBaseURL string

	// WebSocketFeature is the feature specified for the websocket connection
	WebSocketFeature string

	// Indicates whether to print full JSON objects to stdout
	PrintJSON bool

	// Indicates whether to filter events formatted with the default or latest API version
	UseLatestAPIVersion bool

	// Indicates whether to skip certificate verification when forwarding webhooks to HTTPS endpoints
	SkipVerify bool

	Log *log.Logger

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

Config provides the configuration of a Proxy

type EndpointClient added in v0.2.6

type EndpointClient struct {
	// URL the client sends POST requests to
	URL string
	// contains filtered or unexported fields
}

EndpointClient is the client used to POST webhook requests to the local endpoint.

func NewEndpointClient added in v0.2.6

func NewEndpointClient(url string, connect bool, events []string, cfg *EndpointConfig) *EndpointClient

NewEndpointClient returns a new EndpointClient.

func (*EndpointClient) Post added in v0.2.6

func (c *EndpointClient) Post(webhookID string, body string, headers map[string]string) error

Post sends a message to the local endpoint.

func (*EndpointClient) SupportsEventType added in v0.2.6

func (c *EndpointClient) SupportsEventType(connect bool, eventType string) bool

SupportsEventType takes an event of a webhook and compares it to the internal list of supported events

type EndpointConfig added in v0.2.6

type EndpointConfig struct {
	HTTPClient *http.Client

	Log *log.Logger

	ResponseHandler EndpointResponseHandler
}

EndpointConfig contains the optional configuration parameters of an EndpointClient.

type EndpointResponseHandler added in v0.2.6

type EndpointResponseHandler interface {
	ProcessResponse(string, *http.Response)
}

ResponseHandler handles a response from the endpoint.

type EndpointResponseHandlerFunc added in v0.2.6

type EndpointResponseHandlerFunc func(string, *http.Response)

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

func (EndpointResponseHandlerFunc) ProcessResponse added in v0.2.6

func (f EndpointResponseHandlerFunc) ProcessResponse(webhookID string, resp *http.Response)

ProcessResponse calls f(webhookID, resp).

type EndpointRoute added in v0.2.6

type EndpointRoute struct {
	// URL is the endpoint's URL.
	URL string

	// Connect indicates whether the endpoint should receive normal (when false) or Connect (when true) events.
	Connect bool

	// EventTypes is the list of event types that should be sent to the endpoint.
	EventTypes []string
}

EndpointRoute describes a local endpoint's routing configuration.

type Proxy

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

A Proxy opens a websocket connection with Stripe, listens for incoming webhook events, forwards them to the local endpoint and sends the response back to Stripe.

func New

func New(cfg *Config) *Proxy

New creates a new Proxy

func (*Proxy) Run

func (p *Proxy) Run() error

Run sets the websocket connection and starts the Goroutines to forward incoming events to the local endpoint.

Jump to

Keyboard shortcuts

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