diff --git a/README.md b/README.md index e3a54fc..c8d9643 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,11 @@ The [examples](examples/) directory contains complete example code. To run the simple [helloworld](examples/helloworld/main.go) example: ```bash # Run __without__ sigsci enabled -go run examples/helloworld/main.go +go run examples/helloworld/main.go localhost:8000 # Run with sigsci-agent listening via a UNIX Domain socket file -go run examples/helloworld/main.go /var/run/sigsci.sock +go run examples/helloworld/main.go localhost:8000 /var/run/sigsci.sock # Run with sigsci-agent listening via a TCP address:port -go run examples/helloworld/main.go localhost:9999 +go run examples/helloworld/main.go localhost:8000 localhost:9999 ``` This will run a HTTP listener on `localhost:8000`, which will send any diff --git a/examples/helloworld/main.go b/examples/helloworld/main.go index 55ef60d..79ac74d 100644 --- a/examples/helloworld/main.go +++ b/examples/helloworld/main.go @@ -11,11 +11,20 @@ import ( ) func main() { + // Get the listener address from the first arg + listenerAddress := "" + if len(os.Args) > 1 { + listenerAddress = os.Args[1] + } + if len(listenerAddress) == 0 { + listenerAddress = "localhost:8000" + } + // Process sigsci-agent rpc-address if passed sigsciAgentNetwork := "unix" sigsciAgentAddress := "" - if len(os.Args) > 1 { - sigsciAgentAddress = os.Args[1] + if len(os.Args) > 2 { + sigsciAgentAddress = os.Args[2] } if !strings.Contains(sigsciAgentAddress, "/") { sigsciAgentNetwork = "tcp" @@ -56,7 +65,7 @@ func main() { // Listen and Serve as usual using the wrapped sigsci handler if enabled s := &http.Server{ Handler: handler, - Addr: "localhost:8000", + Addr: listenerAddress, } log.Printf("Server URL: http://%s/", s.Addr) log.Fatal(s.ListenAndServe())