~sircmpwn/meta.sr.ht

ref: 0.56.17 meta.sr.ht/api/webhooks/middleware.go -rw-r--r-- 638 bytes
b1deacf0Nicolas Schodet Fix field name when validating the PGP key in RegisterAccount 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package webhooks

import (
	"context"
	"net/http"

	"git.sr.ht/~sircmpwn/core-go/webhooks"
	"github.com/99designs/gqlgen/graphql"
)

func NewQueue(schema graphql.ExecutableSchema) *webhooks.WebhookQueue {
	return webhooks.NewQueue(schema)
}

var profileWebhooksCtxKey = &contextKey{"profileWebhooks"}

func Middleware(queue *webhooks.WebhookQueue) func(next http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			ctx := context.WithValue(r.Context(), profileWebhooksCtxKey, queue)
			r = r.WithContext(ctx)
			next.ServeHTTP(w, r)
		})
	}
}