webhook

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChanLogger

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

func NewChanLogger

func NewChanLogger(rc chan<- Request) ChanLogger

func (ChanLogger) Record

func (s ChanLogger) Record(r Request)

type Config

type Config struct {
	Logger Logger
}

type Logger

type Logger interface {
	// TODO consider adding error
	Record(r Request)
}

type Request

type Request struct {
	// The remote IP address (with port)
	RemoteAddr string

	Method string
	Proto  string
	RawURL string

	Header map[string][]string
	Body   string

	ReceivedAt time.Time
}

type RouteLogger

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

RouteLogger is a struct to enable being notified when an request identified by a key has been received by the It satisfies the Logger interface

func NewRouteLogger

func NewRouteLogger(key func(Request) string) *RouteLogger

NewRouteLogger takes a key function which can generate a string key based upon the given Request. This key will be used to notify goroutines blocked on RouteLogger.Wait.

func (*RouteLogger) Delete

func (s *RouteLogger) Delete(key string)

Delete must be called after any successful call to Sent to free allocated resources. Not doing so results in a leak.

func (*RouteLogger) Record

func (s *RouteLogger) Record(r Request)

func (*RouteLogger) Sent

func (s *RouteLogger) Sent(key string) error

Sent prepares RouteLogger to be able to handle the incoming request Sent returns an error if the key already exists in the map. Keys must be unique

func (*RouteLogger) Wait

func (s *RouteLogger) Wait(ctx context.Context, key string) (Request, error)

Wait blocks until it's received a message on the webhook matching the key, or ctx.Done() is triggered. If Wait is called before Sent, an error is returned.

func (*RouteLogger) WaitN

func (s *RouteLogger) WaitN(ctx context.Context, n int, keys ...string) ([]Request, error)

WaitN waits for n events within the given keys. If WaitFor is called before one the the given keys has been sent, an error is returned.

type StdLogger

type StdLogger struct {
}

func (StdLogger) Record

func (s StdLogger) Record(r Request)

type Subscriber

type Subscriber struct {
	RouteLogger *RouteLogger
	// contains filtered or unexported fields
}

Subscriber is a subscriber that listen events from a webhook set at the end of the pipeline.

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(keys ...string) error

Subscribe subscribes to the given keys. It satisfies the e2e.Subscriber interface. Keys should be an event messageId.

func (*Subscriber) Unsubscribe

func (s *Subscriber) Unsubscribe(keys ...string)

Unsubscribe satisfies the e2e.Subscriber interface.

func (*Subscriber) WaitN

func (s *Subscriber) WaitN(ctx context.Context, n int) ([]string, error)

WaitN satisfies the e2e.Subscriber interface.

type Webhook

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

func New

func New(c Config, opts ...func(*Webhook)) *Webhook

func (*Webhook) Close

func (h *Webhook) Close() error

func (*Webhook) ServeHTTP

func (h *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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