search close

Golang Module Install

access_time Updated Jan 11, 2022


Install the Agent

Install the Signal Sciences Agent by following the instructions for your environment here:

Download Prerequisites

The Golang module requires two prerequisite packages to be installed: MessagePack Code Generator and the Signal Sciences custom tlstext package.

The easiest way to install these packages is by using the go get command to download and install these packages directly from their GitHub repositories:

go get -u -t
go get -u -t

Download Golang Module

Download the latest version of the Golang module:

curl -O -L

Extract Golang Module

Extract the Golang module to your $GOPATH ($GOPATH/src/

sudo mkdir -p $GOPATH/src/
sudo tar -xf sigsci-module-golang_latest.tar.gz -C $GOPATH/src/

Wrapping Your Application

You will need to wrap your application in the Signal Sciences Golang module handler for the module to process requests and secure your application.

Note: How to best wrap your application will depend on how your application is designed. The steps listed below are provided as an example, but the methods listed may not be ideal for your specific application. More information about the Golang http package, including alternative methods, can be found here.

  1. In the “import” section of your Golang application, add the following line to import the Golang module:

    sigsci ""
  2. Create a new ServeMux in your main() function to be used with the module by adding this line:

    muxname := http.NewServeMux()
  3. Add functions to the ServeMux by adding mux.handleFunc lines. For example, functions named hellofunc and examplefunc can be added with lines such as these:

    muxname.HandleFunc(“/hello“, hellofunc)
    muxname.HandleFunc(“/example”, examplefunc)
  4. Wrap your ServeMux in the Signal Sciences Golang Module by adding these lines similar to this example:

    wrappername, err := sigsci.NewModule(muxname)
        if err != nil {


  5. Call the wrapper in the method your application uses to serve HTTP requests. For example, if you’re using the ListenAndServe method, then you would use call the wrapper with:

    http.ListenAndServe(“”, wrappername)

Example Application

Below is an example “hello world” application with the Signal Sciences Golang module successfully integrated:

package main

import (

     sigsci ""

func hellofunc(w http.ResponseWriter, r *http.Request) {
     fmt.Fprintf(w, "Hello, world")

func examplefunc(w http.ResponseWriter, r *http.Request) {
     fmt.Fprintf(w, "Example function output")

func main() {
     muxname := http.NewServeMux()
     muxname.HandleFunc("/hello", hellofunc)
     muxname.HandleFunc("/example", examplefunc)

     wrappername, err := sigsci.NewModule(muxname)
     if err != nil {

     http.ListenAndServe("", wrappername)