项目作者: signalsciences

项目描述 :
Signal Sciences module for Go
高级语言: Go
项目地址: git://github.com/signalsciences/sigsci-module-golang.git
创建时间: 2019-08-06T03:19:00Z
项目社区:https://github.com/signalsciences/sigsci-module-golang

开源协议:Other

下载


grc GoDoc

sigsci-module-golang

The Signal Sciences module in Golang allows for integrating your Golang
application directly with the Signal Sciences agent at the source code
level. It is written as a http.Handler wrapper. To
integrate your application with the module, you will need to wrap your
existing handler with the module handler.

:rotating_light: NOTICE :rotating_light:

Effective May 17th 2021 the default branch will change from master to main. Run the following commands to update a local clone:

  1. git branch -m master main
  2. git fetch origin
  3. git branch -u origin/main main
  4. git remote set-head origin -a

Installation

  1. go get github.com/signalsciences/sigsci-module-golang@latest

Example Code Snippet

  1. // Example existing http.Handler
  2. mux := http.NewServeMux()
  3. mux.HandleFunc("/", helloworld)
  4. // Wrap the existing http.Handler with the SigSci module handler
  5. wrapped, err := sigsci.NewModule(
  6. // Existing handler to wrap
  7. mux,
  8. // Any additional module options:
  9. //sigsci.Socket("unix", "/var/run/sigsci.sock"),
  10. //sigsci.Timeout(100 * time.Millisecond),
  11. //sigsci.AnomalySize(512 * 1024),
  12. //sigsci.AnomalyDuration(1 * time.Second),
  13. //sigsci.MaxContentLength(100000),
  14. )
  15. if err != nil {
  16. log.Fatal(err)
  17. }
  18. // Listen and Serve as usual using the wrapped sigsci handler
  19. s := &http.Server{
  20. Handler: wrapped,
  21. Addr: "localhost:8000",
  22. }
  23. log.Fatal(s.ListenAndServe())

Examples

The examples/helloworld directory contains complete example code.

To run the simple helloworld example:

  1. # Syntax:
  2. # go run ./examples/helloworld <listener-address:port> [<sigsci-agent-rpc-address>]
  3. #
  4. # Run WITHOUT sigsci enabled
  5. go run ./examples/helloworld localhost:8000
  6. # Run WITH sigsci-agent listening via a UNIX Domain socket file
  7. go run ./examples/helloworld localhost:8000 /var/run/sigsci.sock
  8. # Run WITH sigsci-agent listening via a TCP address:port
  9. go run ./examples/helloworld localhost:8000 localhost:9999

The above will run a HTTP listener on localhost:8000, which will send any
traffic to this listener to a running sigsci-agent for inspection (if
an agent address is configured).