forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mw_track_endpoints.go
32 lines (25 loc) · 987 Bytes
/
mw_track_endpoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"net/http"
"github.com/TykTechnologies/tyk/apidef"
)
// TrackEndpointMiddleware sets context variables to enable or disable whether Tyk should record analytitcs for a specific path.
type TrackEndpointMiddleware struct {
*BaseMiddleware
}
func (a *TrackEndpointMiddleware) GetName() string {
return "TrackEndpointMiddleware"
}
// ProcessRequest will run any checks on the request on the way through the system, return an error to have the chain fail
func (a *TrackEndpointMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int) {
_, versionPaths, _, _ := a.Spec.GetVersionData(r)
foundTracked, metaTrack := a.Spec.CheckSpecMatchesStatus(r, versionPaths, RequestTracked)
if foundTracked {
ctxSetTrackedPath(r, metaTrack.(*apidef.TrackEndpointMeta).Path)
}
foundDnTrack, _ := a.Spec.CheckSpecMatchesStatus(r, versionPaths, RequestNotTracked)
if foundDnTrack {
ctxSetDoNotTrack(r, true)
}
return nil, 200
}