svixgo

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package svixgo is a wrapper around the github.com/svix/svix-webhooks/go package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWebhook

func NewWebhook(secret string) (*svix.Webhook, error)

NewWebhook creates a new webhook instance with the given secret.

func Verify

func Verify(wh *svix.Webhook, payload []byte, headers http.Header) error

Verify validates the incoming payload against the svix signature headers using the webhooks signing secret.

wh, err := NewWebhook(secret)
if err != nil {
	log.Fatal(err)
}

http.HandleFunc("/webhook", func(w http.ResponseWriter, r *http.Request) {
	headers := r.Header
	payload, err := io.ReadAll(r.Body)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	err = Verify(wh, payload, headers)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	// Do something with the message...

	w.WriteHeader(http.StatusNoContent)

})
http.ListenAndServe(":8080", nil)

Types

This section is empty.

Jump to

Keyboard shortcuts

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