Skip to content

Commit ed45f98

Browse files
docs: make helloworld have a configurable listener address so it can be used as an example in other documentation
1 parent 92bf900 commit ed45f98

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ The [examples](examples/) directory contains complete example code.
4949
To run the simple [helloworld](examples/helloworld/main.go) example:
5050
```bash
5151
# Run __without__ sigsci enabled
52-
go run examples/helloworld/main.go
52+
go run examples/helloworld/main.go localhost:8000
5353
# Run with sigsci-agent listening via a UNIX Domain socket file
54-
go run examples/helloworld/main.go /var/run/sigsci.sock
54+
go run examples/helloworld/main.go localhost:8000 /var/run/sigsci.sock
5555
# Run with sigsci-agent listening via a TCP address:port
56-
go run examples/helloworld/main.go localhost:9999
56+
go run examples/helloworld/main.go localhost:8000 localhost:9999
5757
```
5858

5959
This will run a HTTP listener on `localhost:8000`, which will send any

examples/helloworld/main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ import (
1111
)
1212

1313
func main() {
14+
// Get the listener address from the first arg
15+
listenerAddress := ""
16+
if len(os.Args) > 1 {
17+
listenerAddress = os.Args[1]
18+
}
19+
if len(listenerAddress) == 0 {
20+
listenerAddress = "localhost:8000"
21+
}
22+
1423
// Process sigsci-agent rpc-address if passed
1524
sigsciAgentNetwork := "unix"
1625
sigsciAgentAddress := ""
17-
if len(os.Args) > 1 {
18-
sigsciAgentAddress = os.Args[1]
26+
if len(os.Args) > 2 {
27+
sigsciAgentAddress = os.Args[2]
1928
}
2029
if !strings.Contains(sigsciAgentAddress, "/") {
2130
sigsciAgentNetwork = "tcp"
@@ -56,7 +65,7 @@ func main() {
5665
// Listen and Serve as usual using the wrapped sigsci handler if enabled
5766
s := &http.Server{
5867
Handler: handler,
59-
Addr: "localhost:8000",
68+
Addr: listenerAddress,
6069
}
6170
log.Printf("Server URL: http://%s/", s.Addr)
6271
log.Fatal(s.ListenAndServe())

0 commit comments

Comments
 (0)