diff options
author | Wim <wim@42.be> | 2017-02-18 23:00:46 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-02-18 23:11:48 +0100 |
commit | 930b639cc9cd2d2873302f30303378c0e53816a8 (patch) | |
tree | 8cd3f1d464fb5d4e5607fe16255c35a31a9d8b62 /vendor/github.com/facebookgo/httpdown/httpdown_example/main.go | |
parent | 58483ea70c2c99a352592c5e50686fb03985650e (diff) | |
download | matterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.tar.gz matterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.tar.bz2 matterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.zip |
Update vendor
Diffstat (limited to 'vendor/github.com/facebookgo/httpdown/httpdown_example/main.go')
-rw-r--r-- | vendor/github.com/facebookgo/httpdown/httpdown_example/main.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/facebookgo/httpdown/httpdown_example/main.go b/vendor/github.com/facebookgo/httpdown/httpdown_example/main.go new file mode 100644 index 00000000..9e3c0bff --- /dev/null +++ b/vendor/github.com/facebookgo/httpdown/httpdown_example/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "os" + "time" + + "github.com/facebookgo/httpdown" +) + +func handler(w http.ResponseWriter, r *http.Request) { + duration, err := time.ParseDuration(r.FormValue("duration")) + if err != nil { + http.Error(w, err.Error(), 400) + return + } + fmt.Fprintf(w, "going to sleep %s with pid %d\n", duration, os.Getpid()) + w.(http.Flusher).Flush() + time.Sleep(duration) + fmt.Fprintf(w, "slept %s with pid %d\n", duration, os.Getpid()) +} + +func main() { + server := &http.Server{ + Addr: "127.0.0.1:8080", + Handler: http.HandlerFunc(handler), + } + hd := &httpdown.HTTP{ + StopTimeout: 10 * time.Second, + KillTimeout: 1 * time.Second, + } + + flag.StringVar(&server.Addr, "addr", server.Addr, "http address") + flag.DurationVar(&hd.StopTimeout, "stop-timeout", hd.StopTimeout, "stop timeout") + flag.DurationVar(&hd.KillTimeout, "kill-timeout", hd.KillTimeout, "kill timeout") + flag.Parse() + + if err := httpdown.ListenAndServe(server, hd); err != nil { + panic(err) + } +} |