| 1 |
// Package router provides service routing functionality for shoutrrr notifications. |
| 2 |
// |
| 3 |
// The router package is responsible for routing notification messages to specific |
| 4 |
// notification services based on service URLs. It manages the lifecycle of service |
| 5 |
// instances, handles URL parsing, and provides both synchronous and asynchronous |
| 6 |
// message delivery. |
| 7 |
// |
| 8 |
// # Main Components |
| 9 |
// |
| 10 |
// ServiceRouter (router.go) |
| 11 |
// |
| 12 |
// The primary type that manages notification services and routes messages. |
| 13 |
// ServiceRouter provides methods for: |
| 14 |
// - Initializing services from URLs |
| 15 |
// - Sending messages synchronously and asynchronously |
| 16 |
// - Managing service lifecycles |
| 17 |
// - Queueing and flushing batched messages |
| 18 |
// - Dispatching structured MessageItems to services that implement RichSender |
| 19 |
// - Propagating context.Context to services that implement ContextSender |
| 20 |
// |
| 21 |
// Errors returned from Send/SendAsync/SendItems are wrapped in *types.TargetError |
| 22 |
// so callers can identify which service failed and use errors.Is/errors.As against |
| 23 |
// the underlying error. |
| 24 |
// |
| 25 |
// Service Factory (servicemap.go) |
| 26 |
// |
| 27 |
// Maps service schemes to their factory functions, enabling dynamic service |
| 28 |
// instantiation. Supports over 20 notification services including: |
| 29 |
// - Chat: Discord, Slack, Telegram, Matrix, Mattermost, Teams, etc. |
| 30 |
// - Email: SMTP |
| 31 |
// - Push: Gotify, Pushover, Pushbullet, ntfy, etc. |
| 32 |
// - SMS: Twilio |
| 33 |
// - Incident: PagerDuty, OpsGenie |
| 34 |
// |
| 35 |
// Schema Registry (schema_registry.go) |
| 36 |
// |
| 37 |
// SupportedSchemas and SupportsSchema expose the set of registered service |
| 38 |
// schemes, enabling discovery without constructing a router. |
| 39 |
// |
| 40 |
// Basic usage: |
| 41 |
// |
| 42 |
// router, err := router.New(logger, "slack://webhook/...", "discord://webhook/...") |
| 43 |
// if err != nil { |
| 44 |
// // handle error |
| 45 |
// } |
| 46 |
// |
| 47 |
// errors := router.Send("Hello, World!", nil) |
| 48 |
// |
| 49 |
// For more control, use individual methods: |
| 50 |
// |
| 51 |
// service, err := router.Locate("slack://webhook/...") |
| 52 |
// if err != nil { |
| 53 |
// // handle error |
| 54 |
// } |
| 55 |
// |
| 56 |
// err := service.Send("Hello, World!", nil) |
| 57 |
// |
| 58 |
// For SSRF protection or custom egress control, set HTTPClient for HTTP |
| 59 |
// services such as this slack:// URL. DialContext applies only to non-HTTP |
| 60 |
// TCP services (SMTP and MQTT). |
| 61 |
// |
| 62 |
// opts := types.SenderOptions{ |
| 63 |
// HTTPClient: myClient, |
| 64 |
// DialContext: myDial, |
| 65 |
// } |
| 66 |
// router, err := router.NewWithOptions(logger, opts, "slack://webhook/...") |
| 67 |
// if err != nil { |
| 68 |
// // handle error |
| 69 |
// } |
| 70 |
// |
| 71 |
// errors := router.Send("Hello, World!", nil) |
| 72 |
package router |