From 153ff598d9ce930304192ab336731f0123de9cae Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 28 Apr 2016 16:24:43 +0700 Subject: [PATCH] add command line option which address to bind to --- example/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/example/main.go b/example/main.go index ec24d0ccb..aa2fe6234 100644 --- a/example/main.go +++ b/example/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "flag" "fmt" "net/http" "os" @@ -31,8 +32,10 @@ func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello world!")) }) + bindTo := flag.String("bind", "localhost", "bind to") + flag.Parse() - err = server.ListenAndServe("localhost:6121") + err = server.ListenAndServe(*bindTo + ":6121") if err != nil { panic(err) }