https://github.com/liamg/waitforhttp
Tiny package to wait for an HTTP server to be up
https://github.com/liamg/waitforhttp
Last synced: 5 months ago
JSON representation
Tiny package to wait for an HTTP server to be up
- Host: GitHub
- URL: https://github.com/liamg/waitforhttp
- Owner: liamg
- Created: 2019-09-05T15:58:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-26T13:45:47.000Z (about 5 years ago)
- Last Synced: 2024-10-27T03:46:30.016Z (about 1 year ago)
- Language: Go
- Size: 19.5 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# waitforhttp
[](https://travis-ci.org/liamg/waitforhttp)
Waits for an HTTP server to be serving before returning.
Example:
```go
package main
import (
"fmt"
"net/http"
"time"
"github.com/liamg/waitforhttp"
)
func main() {
server := &http.Server{
Addr: ":8080",
}
go func() {
if err := waitforhttp.Wait(server, time.Second*10); err != nil {
panic(err)
}
fmt.Println("Hooray! Server is listening now!")
}()
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
panic(fmt.Sprintf("Failed to start server: %s", err))
}
}
```