-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathmiddleware_version_check.go
38 lines (29 loc) · 1.07 KB
/
middleware_version_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
34
35
36
37
38
package main
import "errors"
import "net/http"
import ()
// VersionCheck will check whether the version of the requested API the request is accessing has any restrictions on URL endpoints
type VersionCheck struct {
TykMiddleware
}
// New lets you do any initialisations for the object can be done here
func (v *VersionCheck) New() {}
// GetConfig retrieves the configuration from the API config
func (v *VersionCheck) 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 (v *VersionCheck) ProcessRequest(w http.ResponseWriter, r *http.Request, configuration interface{}) (error, int) {
// Check versioning, blacklist, whitelist and ignored status
requestValid, stat := v.TykMiddleware.Spec.IsRequestValid(r)
if requestValid == false {
return errors.New(string(stat)), 409
}
if stat == StatusOkAndIgnore {
handler := SuccessHandler{v.TykMiddleware}
// Skip all other execution
handler.ServeHTTP(w, r)
return nil, 666
}
return nil, 200
}