MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / NewWebhook

Function NewWebhook

db/event_handler.go:53–85  ·  view source on GitHub ↗

Creates a new webhook handler based on the url and filter function.

(ctx context.Context, url string, filterFnString string, timeout *uint64, options map[string]interface{})

Source from the content-addressed store, hash-verified

51
52// Creates a new webhook handler based on the url and filter function.
53func NewWebhook(ctx context.Context, url string, filterFnString string, timeout *uint64, options map[string]interface{}) (*Webhook, error) {
54
55 var err error
56
57 if url == "" {
58 err = errors.New("url parameter must be defined for webhook events.")
59 return nil, err
60 }
61
62 wh := &Webhook{
63 url: url,
64 }
65 if filterFnString != "" {
66 wh.filter = NewJSEventFunction(ctx, filterFnString)
67 }
68
69 if timeout != nil {
70 wh.timeout = time.Duration(*timeout) * time.Second
71 } else {
72 wh.timeout = time.Duration(kDefaultWebhookTimeout) * time.Second
73 }
74
75 // Initialize transport and client
76 transport := base.DefaultHTTPTransport()
77 transport.DisableKeepAlives = false
78 wh.client = &http.Client{Transport: transport, Timeout: wh.timeout}
79
80 if options != nil {
81 wh.options.DocumentChangedWinningRevOnly, _ = options[EventOptionDocumentChangedWinningRevOnly].(bool)
82 }
83
84 return wh, err
85}
86
87// Performs an HTTP POST to the url defined for the handler. If a filter function is defined,
88// calls it to determine whether to POST. The payload for the POST is depends

Callers 6

TestWebhookBasicFunction · 0.85
TestWebhookOverflowsFunction · 0.85
TestWebhookOldDocFunction · 0.85
TestWebhookTimeoutFunction · 0.85
TestUnavailableWebhookFunction · 0.85

Calls 2

DefaultHTTPTransportFunction · 0.92
NewJSEventFunctionFunction · 0.85

Tested by 5

TestWebhookBasicFunction · 0.68
TestWebhookOverflowsFunction · 0.68
TestWebhookOldDocFunction · 0.68
TestWebhookTimeoutFunction · 0.68
TestUnavailableWebhookFunction · 0.68