-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdoc_test.go
45 lines (36 loc) · 919 Bytes
/
doc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package sigsci_test
import (
"fmt"
"log"
"net/http"
"time"
sigsci "github.com/signalsciences/sigsci-module-golang"
)
func helloWorld(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}
func Example() {
// Existing http.Handler
mux := http.NewServeMux()
mux.HandleFunc("/", helloWorld)
// Wrap the existing http.Handler with the SigSci module handler
wrapped, err := sigsci.NewModule(
// Existing handler to wrap
mux,
// Any additional module options:
sigsci.Socket("unix", "/var/run/sigsci.sock"),
sigsci.Timeout(100*time.Millisecond),
sigsci.AnomalySize(512*1024),
sigsci.AnomalyDuration(1*time.Second),
sigsci.MaxContentLength(100000),
)
if err != nil {
log.Fatal(err)
}
// Listen and Serve as usual using the wrapped sigsci handler
s := &http.Server{
Handler: wrapped,
Addr: "localhost:8000",
}
log.Fatal(s.ListenAndServe())
}