Install Sqreen on a Heroku Go App


Quick Start

This Go app example allows to create a Go web server that serves "Hello HTTP!", and deploy it to Heroku.

It uses the official Heroku buildpack for Go (https://github.com/heroku/heroku-buildpack-go) along with Sqreen's (https://github.com/sqreen/heroku-buildpack-go).

You can also click the following Heroku Button to directly deploy this example to Heroku:

Deploy

Instructions

The following instructions allows to setup Sqreen in a Heroku Go app:

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

// 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/v4"
    "github.com/sqreen/go-agent/sdk/middleware/sqecho/v4"
)
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)
}
  • Deploy your Go app to Heroku.

You can then hit the app URL to see the Hello HTTP! web server response, now protected by Sqreen!

Sqreen for Go

More information on Heroku

Learn more about using Sqreen with Heroku on the Heroku Marketplace: