WaitFor is a simple library for implementing dependency checks in your Go application.
Waitfor provides a simple API to wait for your applications dependancies to become available. For example if your application relies on an external database wait for can check that the service is up and listening. This can be useful in container environments where your services DNS name is not registered until the remote service becomes healthy.
See the GoDoc examples for more detail.
-
Install with
go get
:go get -u github.com/davejohnston/waitfor
-
Create a dependancy handler:
var dependancies = waitfor.NewDependencies()()
- Add a dependancy:
dependancies.Add("rest-api", waitfor.ServiceListening("0.0.0.0:9999", 10*time.Second))
dependancies.Add("postgres-db", waitfor.DatabaseReady("postgres", "host=localhost port=5423 user=postgres password=secret dbname=postgres sslmode=disable")
- Wait for the dependancies:
if err := dependancies.Wait(); err != nil {
log.fatal(err)
}