webhook

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	HandleAction(ctx context.Context, req *Request) (*Response, error)
}

Handler is the interface used for implementing webhook handlers.

type HandlerFunc

type HandlerFunc func(ctx context.Context, name string, input []byte) (any, error)

The HandlerFunc type is an adapter to allow the use of ordinary functions as action handlers.

func (HandlerFunc) HandleAction

func (h HandlerFunc) HandleAction(ctx context.Context, req *Request) (*Response, error)

type Request

type Request struct {
	Headers http.Header
	Body    []byte
}

Request is a wrapper for webhook requests.

func (*Request) GetAction

func (r *Request) GetAction() (string, error)

GetAction returns the webhook action.

func (*Request) GetSignatures

func (r *Request) GetSignatures() ([]string, error)

GetSignatures returns the webhook signatures.

func (*Request) GetTimestamp

func (r *Request) GetTimestamp() (string, error)

GetTimestamp returns the webhook timestamp.

type Response

type Response struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
}

Response is a wrapper for webhook responses.

type Webhook

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

Webhook is a parsing and dispatch helper for UserHub webhooks.

func New

func New(signingSecret string, opts ...option.WebhooksOption) *Webhook

New returns a new instance of Webhook.

func (*Webhook) CreateResponse

func (w *Webhook) CreateResponse(ctx context.Context, value any) *Response

CreateResponse creates a response from an object that can be encoded using json.Marshal or error.

func (*Webhook) HandleAction

func (w *Webhook) HandleAction(ctx context.Context, r *Request) *Response

HandleAction executes a handler based on specified Request.

func (*Webhook) OnAction

func (w *Webhook) OnAction(name string, handler Handler) *Webhook

OnAction registers an action handler.

func (*Webhook) OnChallenge

func (w *Webhook) OnChallenge(fn func(ctx context.Context, input *connectionsv1.Challenge) (*connectionsv1.Challenge, error)) *Webhook

OnChallenge registers a handler for the `challenge` action.

func (*Webhook) OnCreateUser

func (w *Webhook) OnCreateUser(fn func(ctx context.Context, input *connectionsv1.CustomUser) (*connectionsv1.CustomUser, error)) *Webhook

OnCreateUser registers a handler for the `users.create` action.

func (*Webhook) OnDefault

func (w *Webhook) OnDefault(fn HandlerFunc) *Webhook

OnDefault registers a fallback action handler.

func (*Webhook) OnDeleteUser

func (w *Webhook) OnDeleteUser(fn func(ctx context.Context, input *connectionsv1.DeleteCustomUserRequest) error) *Webhook

OnDeleteUser registers a handler for the `users.delete` action.

func (*Webhook) OnEvent

func (w *Webhook) OnEvent(fn func(ctx context.Context, input *eventsv1.Event) error) *Webhook

OnEvent registers a handler for the `events.handle` action.

func (*Webhook) OnGetUser

OnGetUser registers a handler for the `users.get` action.

func (*Webhook) OnListUsers

OnListUsers registers a handler for the `users.list` action.

func (*Webhook) OnUpdateUser

func (w *Webhook) OnUpdateUser(fn func(ctx context.Context, input *connectionsv1.CustomUser) (*connectionsv1.CustomUser, error)) *Webhook

OnUpdateUser registers a handler for the `users.update` action.

func (*Webhook) ServeHTTP

func (w *Webhook) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP handles incoming webhook requests.

func (*Webhook) Verify

func (w *Webhook) Verify(req *Request) error

Verify ensures the body matches the specified signature/timestamp and returns an error if verification fails.

Jump to

Keyboard shortcuts

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