@@ -11,45 +11,61 @@ import (
11
11
)
12
12
13
13
func main () {
14
- // Process sigsci-agent rpc-address if passed
15
- sigsciAgentNetwork := "unix"
16
- sigsciAgentAddress := "/var/run/sigsci.sock"
14
+ // Get the listener address from the first arg
15
+ listenerAddress := ""
17
16
if len (os .Args ) > 1 {
18
- sigsciAgentAddress = os .Args [1 ]
17
+ listenerAddress = os .Args [1 ]
18
+ }
19
+ if len (listenerAddress ) == 0 {
20
+ listenerAddress = "localhost:8000"
21
+ }
22
+
23
+ // Process sigsci-agent rpc-address from the optional second arg
24
+ sigsciAgentNetwork := "unix"
25
+ sigsciAgentAddress := ""
26
+ if len (os .Args ) > 2 {
27
+ sigsciAgentAddress = os .Args [2 ]
19
28
}
20
29
if ! strings .Contains (sigsciAgentAddress , "/" ) {
21
30
sigsciAgentNetwork = "tcp"
22
31
}
23
- log .Printf ("Using sigsci-agent address (pass address as program argument to change): %s:%s" , sigsciAgentNetwork , sigsciAgentAddress )
24
32
25
33
// Existing handler, in this case a simple http.ServeMux,
26
34
// but could be any http.Handler in the application
27
35
mux := http .NewServeMux ()
28
36
mux .HandleFunc ("/" , helloworld )
37
+ handler := http .Handler (mux )
38
+
39
+ if len (sigsciAgentAddress ) > 0 {
40
+ // Wrap the existing http.Handler with the SigSci module handler
41
+ wrapped , err := sigsci .NewModule (
42
+ // Existing handler to wrap
43
+ mux ,
44
+
45
+ // Any additional module options:
46
+ sigsci .Socket (sigsciAgentNetwork , sigsciAgentAddress ),
47
+ //sigsci.Timeout(100 * time.Millisecond),
48
+ //sigsci.AnomalySize(512 * 1024),
49
+ //sigsci.AnomalyDuration(1 * time.Second),
50
+ //sigsci.MaxContentLength(100000),
29
51
30
- // Wrap the existing http.Handler with the SigSci module handler
31
- wrapped , err := sigsci .NewModule (
32
- // Existing handler to wrap
33
- mux ,
52
+ // Turn on debug logging for this example (do not use in production)
53
+ sigsci .Debug (true ),
54
+ )
55
+ if err != nil {
56
+ log .Fatal (err )
57
+ }
34
58
35
- // Any additional module options:
36
- sigsci .Socket (sigsciAgentNetwork , sigsciAgentAddress ),
37
- //sigsci.Timeout(100 * time.Millisecond),
38
- //sigsci.AnomalySize(512 * 1024),
39
- //sigsci.AnomalyDuration(1 * time.Second),
40
- //sigsci.MaxContentLength(100000),
59
+ log .Printf ("Signal Sciences agent RPC address: %s:%s" , sigsciAgentNetwork , sigsciAgentAddress )
41
60
42
- // Turn on debug logging for this example (do not use in production)
43
- sigsci .Debug (true ),
44
- )
45
- if err != nil {
46
- log .Fatal (err )
61
+ // Use the wrapped sigsci handler
62
+ handler = wrapped
47
63
}
48
64
49
- // Listen and Serve as usual using the wrapped sigsci handler
65
+ // Listen and Serve as usual using the wrapped sigsci handler if enabled
50
66
s := & http.Server {
51
- Handler : wrapped ,
52
- Addr : "localhost:8000" ,
67
+ Handler : handler ,
68
+ Addr : listenerAddress ,
53
69
}
54
70
log .Printf ("Server URL: http://%s/" , s .Addr )
55
71
log .Fatal (s .ListenAndServe ())
0 commit comments