You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-9Lines changed: 21 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,10 +55,20 @@ func main() {
55
55
}
56
56
```
57
57
58
+
**Note:** Additional middlewares are provided for different routers.
59
+
58
60
Build and deploy your app and that's it. Your API is being tracked in the Speakeasy workspace you just created
59
61
and will be visible on the dashboard next time you log in. Visit our [docs site](https://docs.speakeasyapi.dev/) to
60
62
learn more.
61
63
64
+
#### Mux-based routers
65
+
66
+
For middlewares based on the net/http `ServeMux` interface, use `speakeasy.MiddlewareWithMux`.
67
+
68
+
#### Gin
69
+
70
+
For the [gin](https://github.com/gin-gonic/gin) framework, use `speakeasy.GinMiddlware`.
71
+
62
72
### Advanced configuration
63
73
64
74
The Speakeasy SDK provides both a global and per Api configuration option. If you want to use the SDK to track multiple Apis or Versions from the same service you can configure individual instances of the SDK, like so:
@@ -118,9 +128,10 @@ To help the SDK in these situations you can provide path hints per request handl
118
128
```go
119
129
funcMyHandler(whttp.ResponseWriter, r *http.Request) {
120
130
// Provide a path hint for the request using the OpenAPI Path Templating format: https://swagger.io/specification/#path-templating-matching
121
-
ctrl:= speakeasy.MiddlewareController(req)
122
-
ctrl.PathHint("/v1/users/{id}")
123
-
131
+
ctrl, ok:= speakeasy.MiddlewareController(req)
132
+
if ok {
133
+
ctrl.PathHint("/v1/users/{id}")
134
+
}
124
135
// the rest of your handlers code
125
136
}
126
137
```
@@ -138,9 +149,10 @@ To help associate requests with customers/users of your APIs you can provide a c
138
149
139
150
```go
140
151
funcMyHandler(whttp.ResponseWriter, r *http.Request) {
141
-
ctrl:= speakeasy.MiddlewareController(req)
142
-
ctrl.CustomerID("a-customers-id") // This customer ID will be used to associate this instance of a request with your customers/users
143
-
152
+
ctrl, ok:= speakeasy.MiddlewareController(req)
153
+
if ok {
154
+
ctrl.CustomerID("a-customers-id") // This customer ID will be used to associate this instance of a request with your customers/users
155
+
}
144
156
// the rest of your handlers code
145
157
}
146
158
```
@@ -157,7 +169,7 @@ But if you would like to be more selective you can mask certain sensitive data u
157
169
158
170
```go
159
171
funcMyHandler(whttp.ResponseWriter, r *http.Request) {
160
-
ctrl:= speakeasy.MiddlewareController(req)
172
+
ctrl, _:= speakeasy.MiddlewareController(req)
161
173
ctrl.Masking(speakeasy.WithRequestHeaderMask("Authorization")) // Mask the Authorization header in the request
162
174
163
175
// the rest of your handlers code
@@ -190,7 +202,7 @@ r.Use(speakeasy.Middleware)
190
202
r.Use(func (next http.Handler) http.Handler {
191
203
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
192
204
// Mask the Authorization header in the request for all requests served by this middleware
// Or finally if you have a handler that you would like to generate an access token from, you can get the SDK instance for that handler from the middleware controller and use the `GetEmbedAccessToken` function it.
235
247
funcMyHandler(whttp.ResponseWriter, r *http.Request) {
0 commit comments