Skip to content

Instantly share code, notes, and snippets.

@thbishop
Created October 30, 2014 21:26
Show Gist options
  • Save thbishop/3c2cce23f459509b1c61 to your computer and use it in GitHub Desktop.
Save thbishop/3c2cce23f459509b1c61 to your computer and use it in GitHub Desktop.
basic golang manners impl
package main
import (
"fmt"
"github.com/braintree/manners"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(10000 * time.Millisecond)
fmt.Fprintf(w, "Foo Bar")
})
server := manners.NewServer()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
fmt.Printf("Got a signal %v", sig)
server.Shutdown <- true
}()
fmt.Printf("Starting server")
err := server.ListenAndServe(":7000", nil)
if err != nil {
fmt.Printf("Error: %s", err)
}
fmt.Printf("Exiting")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment