Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.

1995parham-learning/refurbed-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notifier

An HTTP notification client library and CLI tool written in Go.

The Library

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.

Design

  • 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.Transport is 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.

API

// 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()

The Executable

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.

Build

go build -o notify ./cmd/notify

Usage

notify --url=URL [<flags>]

Flags:
    --help                 Show help.
    --url URL              Target URL to send notifications to (required).
-i, --interval=5s          Notification interval.

Example

# 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.txt

Testing

go test ./...

About

Refurbed notifier backend assignment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages