How djui/await works
Project type and purpose
• This is a Go-based command-line tool (“await”) whose sole purpose is to block until a set of “resources” (HTTP endpoints, TCP ports, files, databases, AMQP brokers, or arbitrary commands) become available, and then (optionally) run a user command.
• It’s designed as an extensible, self-contained CLI utility, often used in Docker Compose entrypoints or similar orchestration contexts.
File structure
• Top-level entrypoint:
• main.go / main_test.go – sets up CLI flags, parses arguments, and invokes the awaiter.
• Core orchestration:
• awaiter.go – central loop that takes a list of Resource objects, polls them until ready or timeout.
• resource.go – defines the Resource interface and common parsing/fragment mechanics.
• Resource implementations (strategy/plugin pattern):
• http.go / http_test.go
• websocket.go
• tcp.go
• file.go / resource_test.go
• postgresql.go
• mysql.go
• amqp.go
• command.go
• Supporting modules:
• log.go – logging, verbosity levels
• <other helper files> (none)
• Build & dependency files:
• Makefile, go.mod, go.sum
Insights from README
• The tool exposes flags (-t, -v, -i, etc.) to control timeout, verbosity, input source, and whether to force execution on failure.
• Supports resource URL syntax plus a generic “command” fallback.
• After successful waits, it can exec a child command.
a. Main components:
1. CLI Layer (main.go)
2. Parser & Config (flag parsing + resource URL/file input)
3. Awaiter Engine (awaiter.go)
4. Resource Strategy Modules (http, tcp, websocket, file, postgresql, mysql, amqp, command)
5. Logging Subsystem (log.go)
6. Child Command Executor (command.go)
7. External Resources (web servers, databases, message brokers, file system, shell commands)
b. Relationships & interactions:
• User invokes CLI → CLI Layer parses flags → builds a list of Resource objects
• Awaiter Engine receives the Resource list and the timeout/verbosity settings
• For each Resource, Awaiter calls its Check() method in a loop until it reports “available” or timeout
• Logging Subsystem records each check attempt (verbosity drives log level)
• Once all resources are ready (or if forced after timeout), Child Command Executor runs the user-specified command and returns its exit code
c. Architectural patterns & principles:
• Strategy pattern: each resource type implements a common interface (Resource)
• Single-responsibility: parsing, waiting, logging, and execution are cleanly separated
• Pluggability: new resource types can be added by implementing the Resource interface
d. Key technologies & libraries:
• Go standard library (net/http, net, database/sql, os/exec, etc.)
• lib/pq for PostgreSQL
• go-sql-driver/mysql for MySQL
• amqp client library (in amqp.go)
Final recommendations
• Every resource type module as its own sub-component to show the plugin boundary.
• Loop in the Awaiter Engine to convey “poll until available or timeout.”
• Don’t omit the child command execution path after successful waits.