An HTTP notification client library and CLI tool written in Go.
A library that implements an HTTP notification client. A client is configured with a URL to which notifications are sent. It exposes a function that takes messages and notifies about them by sending HTTP POST requests to the configured URL with the message content in the request body.
- Non-blocking
Notify()— messages are enqueued onto a buffered channel and processed by a fixed worker pool. - Bounded concurrency — a configurable number of workers limits parallel HTTP requests, preventing file descriptor exhaustion.
- Connection pooling — the underlying
http.Transportis tuned to match the worker count (MaxConnsPerHost,MaxIdleConnsPerHost). - Async error reporting — failures are sent to an error channel the caller can drain at their own pace.
// Create a notifier targeting a URL.
n := notifier.New("http://localhost:8080/notify",
notifier.WithWorkers(10), // default: 10
notifier.WithQueueSize(1000), // default: 1000
)
// Enqueue a message (non-blocking while queue has capacity).
err := n.Notify(ctx, "hello world")
// Read errors asynchronously.
go func() {
for err := range n.Errors() {
log.Println(err)
}
}()
// Drain in-flight requests and release resources.
n.Close()A CLI program that uses the library above. It reads from stdin and sends new messages every configurable interval. Each line is interpreted as a new message.
The program implements graceful shutdown on SIGINT/SIGTERM.
go build -o notify ./cmd/notifynotify --url=URL [<flags>]
Flags:
--help Show help.
--url URL Target URL to send notifications to (required).
-i, --interval=5s Notification interval.
# Send each line of messages.txt as an HTTP POST every 5 seconds.
$ ./notify --url http://localhost:8080/notify < messages.txt
# Custom interval.
$ ./notify --url http://localhost:8080/notify --interval 2s < messages.txtgo test ./...