Skip to content

liamg/waitforhttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Tiny package to wait for an HTTP server to be up

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published