Treblle for Go

Introduction

Trebble middleware for Go works with applications based on net/http.

Installation

Trebble uses Go Modules to manage dependencies.

go get github.com/treblle/treblle-go

Basic configuration

Configure Treblle at the start of your main() function:

import "github.com/treblle/treblle-go"

func main() {
	treblle.Configure(treblle.Configuration{
		APIKey:     "YOUR API KEY HERE",
		ProjectID:  "YOUR PROJECT ID HERE",
        AdditionalFieldsToMask: []string{"password", "card_number"}, // optional, specify additional fields to mask
	}

    // rest of your program.
}

After that, just use the middleware with any of your handlers:

mux := http.NewServeMux()
mux.Handle("/", treblle.Middleware(http.HandlerFunc(yourHandler)))

gorilla/mux

To setup the treblle.Middleware in gorilla/mux, you can use it as a global middleware:

r := mux.NewRouter()
r.Use(treblle.Middleware)

per-route

You can also use treblle.Middleware as a per-route middleware just like you will use it with net/http:

r := mux.NewRouter()
r.Handle("/", treblle.Middleware(http.HandlerFunc(yourHandler)))

Subroutes

You can also use treblle.Middleware on gorilla/mux subroutes:

r := mux.NewRouter()

apiRouter := r.PathPrefix("/api").Subrouter()

apiRouter.Use(treblle.Middleware) // Set as a middleware for this subroute

apiRouter.HandleFunc("/users", yourHandler)

More Integrations

PHP

JavaScript

Others