MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / NewWebhooks

Method NewWebhooks

pkg/applicationserver/config.go:255–282  ·  view source on GitHub ↗

NewWebhooks returns a new web.Webhooks based on the configuration. If Target is empty, this method returns nil.

(ctx context.Context, server io.Server)

Source from the content-addressed store, hash-verified

253// NewWebhooks returns a new web.Webhooks based on the configuration.
254// If Target is empty, this method returns nil.
255func (c WebhooksConfig) NewWebhooks(ctx context.Context, server io.Server) (web.Webhooks, error) {
256 var target sink.Sink
257 switch c.Target {
258 case "":
259 return nil, nil
260 case "direct":
261 client, err := server.HTTPClient(ctx)
262 if err != nil {
263 return nil, err
264 }
265 client.Timeout = c.Timeout
266 target = sink.NewHTTPClientSink(client)
267 default:
268 return nil, errWebhooksTarget.WithAttributes("target", c.Target)
269 }
270 if c.Registry == nil {
271 return nil, errWebhooksRegistry.New()
272 }
273 if c.UnhealthyAttemptsThreshold > 0 || c.UnhealthyRetryInterval > 0 {
274 registry := web.NewHealthStatusRegistry(c.Registry)
275 registry = web.NewCachedHealthStatusRegistry(registry)
276 target = sink.NewHealthCheckSink(target, registry, c.UnhealthyAttemptsThreshold, c.UnhealthyRetryInterval)
277 }
278 if c.QueueSize > 0 || c.Workers > 0 {
279 target = sink.NewPooledSink(ctx, server, target, c.Workers, c.QueueSize)
280 }
281 return web.NewWebhooks(ctx, server, c.Registry, target, c.Downlinks)
282}
283
284// NewPubSub returns a new pubsub.PubSub based on the configuration.
285// If the registry is nil, it returns nil.

Callers 1

NewFunction · 0.80

Calls 9

NewHTTPClientSinkFunction · 0.92
NewHealthStatusRegistryFunction · 0.92
NewHealthCheckSinkFunction · 0.92
NewPooledSinkFunction · 0.92
NewWebhooksFunction · 0.92
HTTPClientMethod · 0.65
NewMethod · 0.65
WithAttributesMethod · 0.45

Tested by

no test coverage detected