go-agent: github.com/sqreen/go-agent/sdk/middleware/sqecho Index | Files

package sqecho

import "github.com/sqreen/go-agent/sdk/middleware/sqecho"

Index

Package Files

echo.go

func FromContext Uses

func FromContext(c echo.Context) *sdk.HTTPRequestRecord

FromContext allows to access the HTTPRequestRecord from Echo request handlers if present, and nil otherwise. The value is stored in handler contexts by the middleware function, and is of type *HTTPRequestRecord.

Note that Echo's context does not implement the `context.Context` interface, so `sdk.FromContext()` cannot be used with it, hence `FromContext()` in this package to access the SDK context value from Echo's context. `sdk.FromContext()` can still be used on the request context.

func Middleware Uses

func Middleware() echo.MiddlewareFunc

Middleware is Sqreen's middleware function for Echo to monitor and protect the requests Echo receives. It creates and stores the HTTP request record both into the Echo and request contexts so that it can be later accessed from handlers using `sdk.FromContext()` to perform SDK calls.

Note that Echo's context does not implement the `context.Context` interface, so `sdk.FromContext()` cannot be used with it, hence `FromContext()` in this package to access the SDK context value from Echo's context. `sdk.FromContext()` can still be used on the request context.

e := echo.New()
e.Use(sqecho.Middleware())

e.GET("/", func(c echo.Context) {
	// Accessing the SDK through Echo's context
	sqecho.FromContext(c).TrackEvent("my.event.one")
	foo(c.Request())
}

func foo(req *http.Request) {
	// Accessing the SDK through the request context
	sdk.FromContext(req.Context()).TrackEvent("my.event.two")
}

Package sqecho imports 3 packages (graph). Updated 2019-02-07. Refresh now. Tools for package owners.