NewWebhooks returns a new web.Webhooks based on the configuration. If Target is empty, this method returns nil.
(ctx context.Context, server io.Server)
| 253 | // NewWebhooks returns a new web.Webhooks based on the configuration. |
| 254 | // If Target is empty, this method returns nil. |
| 255 | func (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. |
no test coverage detected