-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
698f4a0
commit 6688111
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()) | ||
} |