Skip to content

Commit

Permalink
mw: remove anonymous field stutters
Browse files Browse the repository at this point in the history
We can access t.Spec and tmeta.TemplateData directly. Both stuttered
before - t is already a middleware, and tmeta is already a template.
  • Loading branch information
mvdan committed May 10, 2017
1 parent bce4ba9 commit efc4941
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions api_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ func (a *APISpec) CheckSpecMatchesStatus(url string, method string, rxPaths []UR
case Ignored, BlackList, WhiteList, Cached:
return true, nil
case Transformed:
if method == v.TransformAction.TemplateMeta.Method {
if method == v.TransformAction.Method {
return true, &v.TransformAction
}
case HeaderInjected:
Expand All @@ -914,7 +914,7 @@ func (a *APISpec) CheckSpecMatchesStatus(url string, method string, rxPaths []UR
return true, &v.InjectHeadersResponse
}
case TransformedResponse:
if method == v.TransformResponseAction.TemplateMeta.Method {
if method == v.TransformResponseAction.Method {
return true, &v.TransformResponseAction
}
case HardTimeout:
Expand Down
6 changes: 3 additions & 3 deletions middleware_method_transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (t *TransformMethod) GetConfig() (interface{}, error) {

func (t *TransformMethod) IsEnabledForSpec() bool {
var used bool
for _, version := range t.TykMiddleware.Spec.VersionData.Versions {
for _, version := range t.Spec.VersionData.Versions {
if len(version.ExtendedPaths.MethodTransforms) > 0 {
used = true
break
Expand All @@ -39,8 +39,8 @@ func (t *TransformMethod) IsEnabledForSpec() bool {

// ProcessRequest will run any checks on the request on the way through the system, return an error to have the chain fail
func (t *TransformMethod) ProcessRequest(w http.ResponseWriter, r *http.Request, configuration interface{}) (error, int) {
_, versionPaths, _, _ := t.TykMiddleware.Spec.GetVersionData(r)
found, meta := t.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, MethodTransformed)
_, versionPaths, _, _ := t.Spec.GetVersionData(r)
found, meta := t.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, MethodTransformed)
if found {
mmeta := meta.(*apidef.MethodTransformMeta)

Expand Down
6 changes: 3 additions & 3 deletions middleware_modify_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (t *TransformHeaders) GetConfig() (interface{}, error) {

func (t *TransformHeaders) IsEnabledForSpec() bool {
var used bool
for _, version := range t.TykMiddleware.Spec.VersionData.Versions {
for _, version := range t.Spec.VersionData.Versions {
if len(version.ExtendedPaths.TransformHeader) > 0 ||
len(version.GlobalHeaders) > 0 ||
len(version.GlobalHeadersRemove) > 0 {
Expand Down Expand Up @@ -125,7 +125,7 @@ func (t *TransformHeaders) iterateAddHeaders(kv map[string]string, r *http.Reque

// ProcessRequest will run any checks on the request on the way through the system, return an error to have the chain fail
func (t *TransformHeaders) ProcessRequest(w http.ResponseWriter, r *http.Request, configuration interface{}) (error, int) {
vInfo, versionPaths, _, _ := t.TykMiddleware.Spec.GetVersionData(r)
vInfo, versionPaths, _, _ := t.Spec.GetVersionData(r)

// Manage global headers first - remove
for _, gdKey := range vInfo.GlobalHeadersRemove {
Expand All @@ -138,7 +138,7 @@ func (t *TransformHeaders) ProcessRequest(w http.ResponseWriter, r *http.Request
t.iterateAddHeaders(vInfo.GlobalHeaders, r)
}

found, meta := t.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, HeaderInjected)
found, meta := t.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, HeaderInjected)
if found {
hmeta := meta.(*apidef.HeaderInjectionMeta)
for _, dKey := range hmeta.DeleteHeaders {
Expand Down
6 changes: 3 additions & 3 deletions middleware_request_size_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (t *RequestSizeLimitMiddleware) GetConfig() (interface{}, error) {

func (t *RequestSizeLimitMiddleware) IsEnabledForSpec() bool {
var used bool
for _, version := range t.TykMiddleware.Spec.VersionData.Versions {
for _, version := range t.Spec.VersionData.Versions {
if len(version.ExtendedPaths.SizeLimit) > 0 {
used = true
break
Expand Down Expand Up @@ -83,7 +83,7 @@ func (t *RequestSizeLimitMiddleware) checkRequestLimit(r *http.Request, sizeLimi
func (t *RequestSizeLimitMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, configuration interface{}) (error, int) {
log.Debug("Request size limiter active")

vInfo, versionPaths, _, _ := t.TykMiddleware.Spec.GetVersionData(r)
vInfo, versionPaths, _, _ := t.Spec.GetVersionData(r)

log.Debug("Global limit is: ", vInfo.GlobalSizeLimit)
// Manage global headers first
Expand All @@ -102,7 +102,7 @@ func (t *RequestSizeLimitMiddleware) ProcessRequest(w http.ResponseWriter, r *ht
}

// If there's a potential match, try to match
found, meta := t.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, RequestSizeLimit)
found, meta := t.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, RequestSizeLimit)
if found {
log.Debug("Request size limit matched for this URL, checking...")
rmeta := meta.(*apidef.RequestSizeMeta)
Expand Down
10 changes: 5 additions & 5 deletions middleware_transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (t *TransformMiddleware) GetConfig() (interface{}, error) {

func (t *TransformMiddleware) IsEnabledForSpec() bool {
var used bool
for _, version := range t.TykMiddleware.Spec.VersionData.Versions {
for _, version := range t.Spec.VersionData.Versions {
if len(version.ExtendedPaths.Transform) > 0 {
used = true
break
Expand All @@ -50,8 +50,8 @@ func (t *TransformMiddleware) IsEnabledForSpec() bool {

// ProcessRequest will run any checks on the request on the way through the system, return an error to have the chain fail
func (t *TransformMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, configuration interface{}) (error, int) {
_, versionPaths, _, _ := t.TykMiddleware.Spec.GetVersionData(r)
found, meta := t.TykMiddleware.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, Transformed)
_, versionPaths, _, _ := t.Spec.GetVersionData(r)
found, meta := t.Spec.CheckSpecMatchesStatus(r.URL.Path, r.Method, versionPaths, Transformed)
if !found {
return nil, 200
}
Expand All @@ -66,7 +66,7 @@ func (t *TransformMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Requ

// Put into an interface:
var bodyData interface{}
switch tmeta.TemplateMeta.TemplateData.Input {
switch tmeta.TemplateData.Input {
case apidef.RequestXML:
mxj.XmlCharsetReader = WrappedCharsetReader
var err error
Expand All @@ -86,7 +86,7 @@ func (t *TransformMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Requ
bodyData = make(map[string]interface{})
}

if tmeta.TemplateMeta.TemplateData.EnableSession {
if tmeta.TemplateData.EnableSession {
ses := context.Get(r, SessionData).(SessionState)
switch x := bodyData.(type) {
case map[string]interface{}:
Expand Down
2 changes: 1 addition & 1 deletion res_handler_transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (rt ResponseTransformMiddleware) HandleResponse(rw http.ResponseWriter, res

// Put into an interface:
var bodyData interface{}
switch tmeta.TemplateMeta.TemplateData.Input {
switch tmeta.TemplateData.Input {
case apidef.RequestXML:
mxj.XmlCharsetReader = WrappedCharsetReader
bodyData, err = mxj.NewMapXml(body) // unmarshal
Expand Down

0 comments on commit efc4941

Please sign in to comment.