Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit a15efb9

Browse files
authored
Merge pull request #23 from highlight-run/cameron/hig-1438-add-gorilla-mux-example-to-go-client
Create gorilla/mux middleware and example
2 parents 9d16d05 + 7a85928 commit a15efb9

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package gorillamux
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/highlight-run/highlight-go"
7+
)
8+
9+
// Middleware is a gorilla/mux compatible middleware
10+
// use as follows:
11+
//
12+
// import highlightgorilla "github.com/highlight-run/highlight-go/middleware/gorillamux"
13+
// ...
14+
// r.Use(highlightgorilla.Middleware)
15+
//
16+
func Middleware(next http.Handler) http.Handler {
17+
fn := func(w http.ResponseWriter, r *http.Request) {
18+
ctx := highlight.InterceptRequest(r)
19+
r = r.WithContext(ctx)
20+
next.ServeHTTP(w, r)
21+
}
22+
return http.HandlerFunc(fn)
23+
}

0 commit comments

Comments
 (0)