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