go-web-middleware

module
v0.0.0-...-c80c473 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2020 License: MIT

README

go-web-middleware

Import Package

    go get github.com/BigBasket/go-web-middleware

The Objective of this package is to manage common middlewares needed for golang web applications.

JWT-RSA

web apis that are using rsa-jwt token for security can instrument the middleware to parse and validate the token.

import (
    "github.com/BigBasket/go-web-middleware/auth/jwt"
    "github.com/gorilla/mux"
    "github.com/lestrrat-go/jwx/jwa"
)

func testHandler (w http.ResponseWriter, r *http.Request) {
    w.Write(http.StatusOK)
}

func main() {
    router := mux.NewRouter()
    jwtDecode := &RSADecode{
        PublicKey : "key" // base64 encoded rsa public key
        Algorithm: jwa.RS256
    }
    router.Use(jwtDecode.InstrumentJWTBearerToken)
    router.HandleFunc("/order/1", testHandler).Methods(http.MethodGet)
}

NewRelic

import (
    "github.com/BigBasket/go-web-middleware/profiling/newrelic"
    log "github.com/sirupsen/logrus"
)

func testHandler (w http.ResponseWriter, r *http.Request) {
    tx := newrelic.FetchTransaction(r.Context())
    // use the newrelic transaction for creating segments etc..
    w.Write(http.StatusOK)
}

func main() {
    router := mux.NewRouter()
    nConn, err := NewConnection(ctx, ConnectionConfig{
		newrelic.Config{AppName: "newrelic-test",
			License: "testkey"},
	})
	if err != nil {
        // handle errors
		return
    }
    router.Use(nConn.InstrumentNewRelic)
    router.HandleFunc("/order/1", testHandler).Methods(http.MethodGet)
}

XTracker

import (
    "github.com/BigBasket/go-web-middleware/profiling/tracker"
)

func testHandler (w http.ResponseWriter, r *http.Request) {
    tracker := FetchXTracker(r.Context())
    w.Write(http.StatusOK)
}

func main() {
    router := mux.NewRouter()
    router.Use(profiling.InstrumentXTracker)
    router.HandleFunc("/order/1", testHandler).Methods(http.MethodGet)
}

Directories

Path Synopsis
auth
jwt
profiling

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL