forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware_rate_check.go
33 lines (25 loc) · 943 Bytes
/
middleware_rate_check.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
33
package main
import (
"net/http"
)
// ModifiedMiddleware is a sample custom middleware component, must inherit TykMiddleware
// so you have access to spec and definition data
type RateCheckMW struct {
*TykMiddleware
}
func (m *RateCheckMW) GetName() string {
return "RateCheckMW"
}
// New lets you do any initialisations for the object can be done here
func (m *RateCheckMW) New() {}
func (m *RateCheckMW) IsEnabledForSpec() bool { return true }
// GetConfig retrieves the configuration from the API config - we user mapstructure for this for simplicity
func (m *RateCheckMW) GetConfig() (interface{}, error) {
return nil, nil
}
// ProcessRequest will run any checks on the request on the way through the system, return an error to have the chain fail
func (m *RateCheckMW) ProcessRequest(w http.ResponseWriter, r *http.Request, configuration interface{}) (error, int) {
// Let's track r/ps
GlobalRate.Incr(1)
return nil, 200
}