Install the Go microagent from examples

Install on a Go app in Docker

Use the Go app example to create a Docker image of a Go web server that serves Hello HTTP!. Each example below uses the official golang docker image which contains everything required to compile a Go program with a Sqreen Microagent.

Alternatively, you can install the microagent in a Go app in Docker using the regular Install procedure.

Build the Docker image example

Build the Docker image and tag it with the image name hello-sqreen.

examples/docker$ docker build -t hello-sqreen:debian -f debian/Dockerfile .
Refer to Debian example in Github.

examples/docker$ docker build -t hello-sqreen -f alpine/Dockerfile .
Refer to Alpine example in Github.

examples/docker$ docker build -t hello-sqreen -f alpine/Dockerfile .
Refer to Scratch example in Github.

Run the Docker image

  1. If you have not already done soe, sign up to create your Sqreen account.
  2. From the Sqreen Dashboard, Connect a new application and retrieve its token.
  3. Run the Docker image with the microagent by passing the Sqreen token.
    examples/docker$ docker run -t -p 8080:8080 -e SQREEN_TOKEN="your token" -e SQREEN_APP_NAME="your app name" --rm hello-sqreen
    

Install on a Go app in Heroku

Heroku is a Platform as a Service (PaaS) that hosts web applications. Sqreen supports Heroku for Go applications.

Use the Go app example to create, then deploy, a Go web server that serves Hello HTTP!. The example uses the official Heroku buildpack for Go and the Sqreen buildpack for Go.

1. Add the Sqreen buildpack https://github.com/sqreen/heroku-buildpack-go before the official heroku-buildpack-go.

2. Add the Sqreen Heroku Addon.

3. Add Sqreen's HTTP middleware for your framework.

// Code snippet for net/http
package main
import (
    "github.com/gin-gonic/gin"
    "github.com/sqreen/go-agent/sdk/middleware/sqhttp"
)
func main() {
    mux := http.NewServeMux()
    // ...
    // Wrap your ServeMux with Sqreen's middleware function
    http.ListenAndServe(":http", sqhttp.Middleware(mux))
}
// Code snippet for gin
package main
import (
    "github.com/gin-gonic/gin"
    "github.com/sqreen/go-agent/sdk/middleware/sqgin"
)
func main() {
    router := gin.New()
    router.Use(sqgin.Middleware())
    // ...
}
// Code snippet for echo
package main
import (
    "github.com/labstack/echo"
    "github.com/sqreen/go-agent/sdk/middleware/sqecho"
)
func main() {
    router := echo.New()
    router.Use(sqgin.Middleware())
    // ...
}
// Code snippet for gorilla/mux
package main
import (
    "github.com/gorilla/mux"
    "github.com/sqreen/go-agent/sdk/middleware/sqhttp"
)
func main() {
    router := mux.NewRouter()
    // Wrap your Gorilla Mux with Sqreen's middleware function
    router.Use(sqhttp.Middleware)
    // ...
}
// Code snippet for beego
package main
import (
    "github.com/astaxie/beego"
    "github.com/sqreen/go-agent/sdk/middleware/sqhttp"
)
func main() {
    app := beego.NewApp()
    // ...
    app.Run(sqhttp.Middleware)
}

4. Deploy your Go app to Heroku.

5. Navigate to the application's URL to see the Hello HTTP! web app server response.

Learn more about using Sqreen with Heroku:

Install on a Go app on Google App Engine

Use the Go app example to create, then deploy, a Go web server that serves Hello HTTP!. The example first uses Google Cloud Build with a multi-stage Docker file to build the Docker image containing the Go server, then deploys to Google App Engine using the flexible environment.

Alternatively, you can install the microagent in a Go app on Google App Engine using the regular Install procedure.

  1. The steps below assume that you have set $PROJECT_ID to the name of your Google Cloud project. You can apply this setting by executing export PROJECT_ID=my-project where my-project is your project name.
  2. Create the Docker image with Cloud Build.
    $ gcloud builds submit --config=cloudbuild.yaml .
    
  3. If you have not done so already, sign up to create your Sqreen account.
  4. From the Sqreen Dashboard, Connect a new application and retrieve its token.
  5. Deploy the Docker image to Google App Engine flexible environment.
    $ gcloud app deploy --image-url=gcr.io/$PROJECT_ID/sqreen-go-hello-http app.yaml
    
  6. Navigate to the application's URL to see the Hello HTTP! web app server response.
  7. Be sure to shut down your Google App Engine deployment to avoid billing charges for a running service.