Skip to content

Commit

Permalink
docs: make helloworld have a configurable listener address so it can …
Browse files Browse the repository at this point in the history
…be used as an example in other documentation
  • Loading branch information
brectanus-sigsci committed Sep 17, 2019
1 parent 92bf900 commit ed45f98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions examples/helloworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit ed45f98

Please sign in to comment.