Categorygithub.com/liamg/waitforhttp
repositorypackage
1.0.0
Repository: https://github.com/liamg/waitforhttp.git
Documentation: pkg.go.dev

# README

waitforhttp

Travis

Waits for an HTTP server to be serving before returning.

Example:

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))
    }
}