-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoorbadge.gen.go
More file actions
616 lines (516 loc) · 20.3 KB
/
doorbadge.gen.go
File metadata and controls
616 lines (516 loc) · 20.3 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
// Code generated by oapi-codegen; DO NOT EDIT.
package doorbadge
import (
"bytes"
"compress/gzip"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
"sync"
oapiCodegenParamsPkg "github.com/oapi-codegen/oapi-codegen-exp/runtime/params"
oapiCodegenTypesPkg "github.com/oapi-codegen/oapi-codegen-exp/runtime/types"
)
// #/components/schemas/WebhookRegistration
type WebhookRegistration struct {
// URL to receive webhook events
URL string `form:"url" json:"url"`
}
// ApplyDefaults sets default values for fields that are nil.
func (s *WebhookRegistration) ApplyDefaults() {
}
// #/components/schemas/WebhookRegistrationResponse
type WebhookRegistrationResponse struct {
// Unique identifier for this webhook registration
ID oapiCodegenTypesPkg.UUID `form:"id" json:"id"`
}
// ApplyDefaults sets default values for fields that are nil.
func (s *WebhookRegistrationResponse) ApplyDefaults() {
}
// #/components/schemas/Person
type Person struct {
// Name of the person who badged in or out
Name string `form:"name" json:"name"`
}
// ApplyDefaults sets default values for fields that are nil.
func (s *Person) ApplyDefaults() {
}
// #/components/schemas/Error
type Error struct {
// Error code
Code int32 `form:"code" json:"code"`
// Error message
Message string `form:"message" json:"message"`
}
// ApplyDefaults sets default values for fields that are nil.
func (s *Error) ApplyDefaults() {
}
// #/paths//api/webhook/{kind}/post/parameters/0/schema
type PostAPIWebhookKindParameter string
const (
EnterEvent PostAPIWebhookKindParameter = "enterEvent"
ExitEvent PostAPIWebhookKindParameter = "exitEvent"
)
// Base64-encoded, gzip-compressed OpenAPI spec.
var openAPISpecJSON = []string{
"H4sIAAAAAAAC/9RWTY/bNhC961cM0gI+RfLu9qTbJuvDAkGycFL0TItjaxKJZIaUvEbb/16Q1GdX3l0D",
"RZv6ZEnDmfceh4+jDSphKIc3N+lVun6TkNrrPAFokS1plcNVuk7XCYAjV2EOd1ozvBPygLBFIZETAIm2",
"YDIuxP+RAADcgvSBuxDIIRAscksFgiuFA4m1VtaxcGjhk0F1+3APN+kVHHFXav3NpiHP+4pQOQuMB7IO",
"GfaaAZVD3rSoHAglAR/JxadhLXwpMdQL+ABYKKnr6gQHVBhrRmjYhvQ+jdKO9oQWRFUN9VBC5f8o5ICo",
"ogKVxTxkVaLGHG6NKEqE66ASQMNVDqVzxuZZdjweUxG+p5oPWbfaZh/u328+ft68vU7XaenqKjHCldZn",
"zYShrOOR/f6NlPwzFjPauvgPwDZ1LfiUw7aXRfTcu4iFLfG/Pt6OC4KirkQ4UIsqCgK+7lREOFJVwcOn",
"z1+GVE6HVYZ1SxIl/Lr9AMcSFfpw0SfS+7jdPiHoomi421gAbfxOkFb3ciTy24yFESxq9Hjzoe7bTnaf",
"cXgJQCoHL+LkFeP3hhhlDo4bnHywRYm1yCdvANzJYA7WManD7AOqpp6HegxjCz791LdjMsJA695peRrz",
"nMFWaOVQuWk9YUxFRRAq+2q1mmNZogLwM+M+h9VPWaFro5Vv8SxG2qxTOAoeN2A1ILVG+/4c862u11er",
"afpZY3W5JqdlErnA5SU25/hczGjbMVklI+69aCp3lkqj8NFg4VACMmv+L4hsfOHVExOg3gIkVujwiQnc",
"Ib/KBrZY69b7GxjGlnRjq9PU6HpD2J2AnIX7u8WTOlZ7/Vmlf+Wk7jXXwuXQNEO95Y7+5eWOlrjQ0/+j",
"HupvQr949KpnbpIHZKtVjEUZrH3XUCVHkWddsPm7//1gLhfpPG9s6/NtEMcJxgKpDQ0wmPorJHwk9xoF",
"f+xr4p8VcCzgV3Q14uIF9+6zxpOud1+xmKoUBJl4TMNV70HsJXY0xennseRF9xi8g+kcJT/gON1zGtwy",
"TpDJOS79TXQhp8HBliiRvIRRM3PfOSVF3xsEkqjC7MvdMEh2oMcTLpFk7IwL+fh74BlG4Zp4mdMM/EdR",
"Y5wvEUw8esdSx7leAinQDLpxEXSwxQsxF1ri5LFGa8XhORZ+wVMWpBwekBe2hpS7uT57gjziOYYOwaVC",
"xUw9/L8CAAD//+XREy3yDQAA",
}
// decodeOpenAPISpec decodes and decompresses the embedded spec.
func decodeOpenAPISpec() ([]byte, error) {
joined := strings.Join(openAPISpecJSON, "")
raw, err := base64.StdEncoding.DecodeString(joined)
if err != nil {
return nil, fmt.Errorf("decoding base64: %w", err)
}
r, err := gzip.NewReader(bytes.NewReader(raw))
if err != nil {
return nil, fmt.Errorf("creating gzip reader: %w", err)
}
defer r.Close()
var out bytes.Buffer
if _, err := out.ReadFrom(r); err != nil {
return nil, fmt.Errorf("decompressing: %w", err)
}
return out.Bytes(), nil
}
// decodeOpenAPISpecCached returns a closure that caches the decoded spec.
func decodeOpenAPISpecCached() func() ([]byte, error) {
var cached []byte
var cachedErr error
var once sync.Once
return func() ([]byte, error) {
once.Do(func() {
cached, cachedErr = decodeOpenAPISpec()
})
return cached, cachedErr
}
}
var openAPISpec = decodeOpenAPISpecCached()
// GetOpenAPISpecJSON returns the raw OpenAPI spec as JSON bytes.
func GetOpenAPISpecJSON() ([]byte, error) {
return openAPISpec()
}
// ServerInterface represents all server handlers.
type ServerInterface interface {
// Deregister a webhook
// (DELETE /api/webhook/{id})
DeregisterWebhook(w http.ResponseWriter, r *http.Request, id oapiCodegenTypesPkg.UUID)
// Register a webhook
// (POST /api/webhook/{kind})
RegisterWebhook(w http.ResponseWriter, r *http.Request, kind string)
}
// ServerInterfaceWrapper converts HTTP requests to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
HandlerMiddlewares []MiddlewareFunc
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
// MiddlewareFunc is a middleware function type.
type MiddlewareFunc func(http.Handler) http.Handler
// DeregisterWebhook operation middleware
func (siw *ServerInterfaceWrapper) DeregisterWebhook(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "id" -------------
var id oapiCodegenTypesPkg.UUID
err = oapiCodegenParamsPkg.BindParameter("id", r.PathValue("id"), &id, oapiCodegenParamsPkg.ParameterOptions{Style: "simple", ParamLocation: oapiCodegenParamsPkg.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "uuid", AllowReserved: false})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.DeregisterWebhook(w, r, id)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// RegisterWebhook operation middleware
func (siw *ServerInterfaceWrapper) RegisterWebhook(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "kind" -------------
var kind string
err = oapiCodegenParamsPkg.BindParameter("kind", r.PathValue("kind"), &kind, oapiCodegenParamsPkg.ParameterOptions{Style: "simple", ParamLocation: oapiCodegenParamsPkg.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", AllowReserved: false})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "kind", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.RegisterWebhook(w, r, kind)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// Handler creates http.Handler with routing matching OpenAPI spec.
func Handler(si ServerInterface) http.Handler {
return HandlerWithOptions(si, StdHTTPServerOptions{})
}
// ServeMux is an abstraction of http.ServeMux.
type ServeMux interface {
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
ServeHTTP(w http.ResponseWriter, r *http.Request)
}
// StdHTTPServerOptions configures the StdHTTP server.
type StdHTTPServerOptions struct {
BaseURL string
BaseRouter ServeMux
Middlewares []MiddlewareFunc
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
func HandlerFromMux(si ServerInterface, m ServeMux) http.Handler {
return HandlerWithOptions(si, StdHTTPServerOptions{
BaseRouter: m,
})
}
// HandlerFromMuxWithBaseURL creates http.Handler with routing and a base URL.
func HandlerFromMuxWithBaseURL(si ServerInterface, m ServeMux, baseURL string) http.Handler {
return HandlerWithOptions(si, StdHTTPServerOptions{
BaseURL: baseURL,
BaseRouter: m,
})
}
// HandlerWithOptions creates http.Handler with additional options.
func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler {
m := options.BaseRouter
if m == nil {
m = http.NewServeMux()
}
if options.ErrorHandlerFunc == nil {
options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
wrapper := ServerInterfaceWrapper{
Handler: si,
HandlerMiddlewares: options.Middlewares,
ErrorHandlerFunc: options.ErrorHandlerFunc,
}
m.HandleFunc("DELETE "+options.BaseURL+"/api/webhook/{id}", wrapper.DeregisterWebhook)
m.HandleFunc("POST "+options.BaseURL+"/api/webhook/{kind}", wrapper.RegisterWebhook)
return m
}
// UnescapedCookieParamError is returned when a cookie parameter cannot be unescaped.
type UnescapedCookieParamError struct {
ParamName string
Err error
}
func (e *UnescapedCookieParamError) Error() string {
return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
}
func (e *UnescapedCookieParamError) Unwrap() error {
return e.Err
}
// UnmarshalingParamError is returned when a parameter cannot be unmarshaled.
type UnmarshalingParamError struct {
ParamName string
Err error
}
func (e *UnmarshalingParamError) Error() string {
return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
}
func (e *UnmarshalingParamError) Unwrap() error {
return e.Err
}
// RequiredParamError is returned when a required parameter is missing.
type RequiredParamError struct {
ParamName string
}
func (e *RequiredParamError) Error() string {
return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
}
// RequiredHeaderError is returned when a required header is missing.
type RequiredHeaderError struct {
ParamName string
Err error
}
func (e *RequiredHeaderError) Error() string {
return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
}
func (e *RequiredHeaderError) Unwrap() error {
return e.Err
}
// InvalidParamFormatError is returned when a parameter has an invalid format.
type InvalidParamFormatError struct {
ParamName string
Err error
}
func (e *InvalidParamFormatError) Error() string {
return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
}
func (e *InvalidParamFormatError) Unwrap() error {
return e.Err
}
// TooManyValuesForParamError is returned when a parameter has too many values.
type TooManyValuesForParamError struct {
ParamName string
Count int
}
func (e *TooManyValuesForParamError) Error() string {
return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
}
type EnterEventJSONRequestBody = Person
type ExitEventJSONRequestBody = Person
// RequestEditorFn is the function signature for the RequestEditor callback function.
// It may already be defined if client code is also generated; this is a compatible redeclaration.
type RequestEditorFn func(ctx context.Context, req *http.Request) error
// HttpRequestDoer performs HTTP requests.
// The standard http.Client implements this interface.
type HttpRequestDoer interface {
Do(req *http.Request) (*http.Response, error)
}
// WebhookInitiator sends webhook requests to target URLs.
// Unlike Client, it has no stored base URL — the full target URL is provided per-call.
type WebhookInitiator struct {
// Doer for performing requests, typically a *http.Client with any
// customized settings, such as certificate chains.
Client HttpRequestDoer
// A list of callbacks for modifying requests which are generated before sending over
// the network.
RequestEditors []RequestEditorFn
}
// WebhookInitiatorOption allows setting custom parameters during construction.
type WebhookInitiatorOption func(*WebhookInitiator) error
// NewWebhookInitiator creates a new WebhookInitiator with reasonable defaults.
func NewWebhookInitiator(opts ...WebhookInitiatorOption) (*WebhookInitiator, error) {
initiator := WebhookInitiator{}
for _, o := range opts {
if err := o(&initiator); err != nil {
return nil, err
}
}
if initiator.Client == nil {
initiator.Client = &http.Client{}
}
return &initiator, nil
}
// WithWebhookHTTPClient allows overriding the default Doer, which is
// automatically created using http.Client. This is useful for tests.
func WithWebhookHTTPClient(doer HttpRequestDoer) WebhookInitiatorOption {
return func(p *WebhookInitiator) error {
p.Client = doer
return nil
}
}
// WithWebhookRequestEditorFn allows setting up a callback function, which will be
// called right before sending the request. This can be used to mutate the request.
func WithWebhookRequestEditorFn(fn RequestEditorFn) WebhookInitiatorOption {
return func(p *WebhookInitiator) error {
p.RequestEditors = append(p.RequestEditors, fn)
return nil
}
}
func (p *WebhookInitiator) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error {
for _, r := range p.RequestEditors {
if err := r(ctx, req); err != nil {
return err
}
}
for _, r := range additionalEditors {
if err := r(ctx, req); err != nil {
return err
}
}
return nil
}
// WebhookInitiatorInterface is the interface specification for the webhook initiator.
type WebhookInitiatorInterface interface {
// EnterEventWithBody sends a POST webhook request
EnterEventWithBody(ctx context.Context, targetURL string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
EnterEvent(ctx context.Context, targetURL string, body EnterEventJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// ExitEventWithBody sends a POST webhook request
ExitEventWithBody(ctx context.Context, targetURL string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
ExitEvent(ctx context.Context, targetURL string, body ExitEventJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
}
// EnterEventWithBody sends a POST webhook request
// Person entered the building
func (p *WebhookInitiator) EnterEventWithBody(ctx context.Context, targetURL string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewEnterEventWebhookRequestWithBody(targetURL, contentType, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := p.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return p.Client.Do(req)
}
// EnterEvent sends a POST webhook request with application/json body
func (p *WebhookInitiator) EnterEvent(ctx context.Context, targetURL string, body EnterEventJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewEnterEventWebhookRequest(targetURL, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := p.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return p.Client.Do(req)
}
// ExitEventWithBody sends a POST webhook request
// Person exited the building
func (p *WebhookInitiator) ExitEventWithBody(ctx context.Context, targetURL string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewExitEventWebhookRequestWithBody(targetURL, contentType, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := p.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return p.Client.Do(req)
}
// ExitEvent sends a POST webhook request with application/json body
func (p *WebhookInitiator) ExitEvent(ctx context.Context, targetURL string, body ExitEventJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewExitEventWebhookRequest(targetURL, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := p.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return p.Client.Do(req)
}
// NewEnterEventWebhookRequest creates a POST request for the webhook with application/json body
func NewEnterEventWebhookRequest(targetURL string, body EnterEventJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
buf, err := json.Marshal(body)
if err != nil {
return nil, err
}
bodyReader = bytes.NewReader(buf)
return NewEnterEventWebhookRequestWithBody(targetURL, "application/json", bodyReader)
}
// NewEnterEventWebhookRequestWithBody creates a POST request for the webhook with any body
func NewEnterEventWebhookRequestWithBody(targetURL string, contentType string, body io.Reader) (*http.Request, error) {
var err error
reqURL, err := url.Parse(targetURL)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", reqURL.String(), body)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", contentType)
return req, nil
}
// NewExitEventWebhookRequest creates a POST request for the webhook with application/json body
func NewExitEventWebhookRequest(targetURL string, body ExitEventJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
buf, err := json.Marshal(body)
if err != nil {
return nil, err
}
bodyReader = bytes.NewReader(buf)
return NewExitEventWebhookRequestWithBody(targetURL, "application/json", bodyReader)
}
// NewExitEventWebhookRequestWithBody creates a POST request for the webhook with any body
func NewExitEventWebhookRequestWithBody(targetURL string, contentType string, body io.Reader) (*http.Request, error) {
var err error
reqURL, err := url.Parse(targetURL)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", reqURL.String(), body)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", contentType)
return req, nil
}
// WebhookHttpError represents an HTTP error response from the webhook.
// The type parameter E is the type of the parsed error body.
type WebhookHttpError[E any] struct {
StatusCode int
Body E
RawBody []byte
}
func (e *WebhookHttpError[E]) Error() string {
return fmt.Sprintf("HTTP %d", e.StatusCode)
}
// SimpleWebhookInitiator wraps WebhookInitiator with typed responses for operations that have
// unambiguous response types. Methods return the success type directly,
// and HTTP errors are returned as *WebhookHttpError[E] where E is the error type.
type SimpleWebhookInitiator struct {
*WebhookInitiator
}
// NewSimpleWebhookInitiator creates a new SimpleWebhookInitiator which wraps a WebhookInitiator.
func NewSimpleWebhookInitiator(opts ...WebhookInitiatorOption) (*SimpleWebhookInitiator, error) {
inner, err := NewWebhookInitiator(opts...)
if err != nil {
return nil, err
}
return &SimpleWebhookInitiator{WebhookInitiator: inner}, nil
}
// WebhookReceiverInterface represents handlers for receiving webhook requests.
type WebhookReceiverInterface interface {
// Person entered the building
// HandleEnterEventWebhook handles the POST webhook request.
HandleEnterEventWebhook(w http.ResponseWriter, r *http.Request)
// Person exited the building
// HandleExitEventWebhook handles the POST webhook request.
HandleExitEventWebhook(w http.ResponseWriter, r *http.Request)
}
// WebhookReceiverMiddlewareFunc is a middleware function for webhook receiver handlers.
type WebhookReceiverMiddlewareFunc func(http.Handler) http.Handler
// EnterEventWebhookHandler returns an http.Handler for the EnterEvent webhook.
// The caller is responsible for registering this handler at the appropriate path.
func EnterEventWebhookHandler(si WebhookReceiverInterface, errHandler func(w http.ResponseWriter, r *http.Request, err error), middlewares ...WebhookReceiverMiddlewareFunc) http.Handler {
if errHandler == nil {
errHandler = func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
si.HandleEnterEventWebhook(w, r)
}))
for _, middleware := range middlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
})
}
// ExitEventWebhookHandler returns an http.Handler for the ExitEvent webhook.
// The caller is responsible for registering this handler at the appropriate path.
func ExitEventWebhookHandler(si WebhookReceiverInterface, errHandler func(w http.ResponseWriter, r *http.Request, err error), middlewares ...WebhookReceiverMiddlewareFunc) http.Handler {
if errHandler == nil {
errHandler = func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
si.HandleExitEventWebhook(w, r)
}))
for _, middleware := range middlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
})
}