Skip to content

Commit

Permalink
remove uses of fmt for lower level operations
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblakeley committed May 8, 2018
1 parent a071c03 commit aa1f481
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
7 changes: 3 additions & 4 deletions event_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/base64"
"errors"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -167,17 +166,17 @@ func (l *LogMessageEventHandler) Init(handlerConf interface{}) error {

// HandleEvent will be fired when the event handler instance is found in an APISpec EventPaths object during a request chain
func (l *LogMessageEventHandler) HandleEvent(em config.EventMessage) {
logMsg := fmt.Sprintf("%s:%s", l.prefix, em.Type)
logMsg := l.prefix + ":" + string(em.Type)

// We can handle specific event types easily
if em.Type == EventQuotaExceeded {
msgConf := em.Meta.(EventKeyFailureMeta)
logMsg = fmt.Sprintf("%s:%s:%s:%s", logMsg, msgConf.Key, msgConf.Origin, msgConf.Path)
logMsg = logMsg + ":" + msgConf.Key + ":" + msgConf.Origin + ":" + msgConf.Path
}

if em.Type == EventBreakerTriggered {
msgConf := em.Meta.(EventCurcuitBreakerMeta)
logMsg = fmt.Sprintf("%s:%s:%s: [STATUS] %v", logMsg, msgConf.APIID, msgConf.Path, msgConf.CircuitEvent)
logMsg = logMsg + ":" + msgConf.APIID + ":" + msgConf.Path + ": [STATUS] " + string(msgConf.CircuitEvent)
}

log.Warning(logMsg)
Expand Down
7 changes: 3 additions & 4 deletions handler_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"encoding/base64"
"fmt"
"net/http"
"runtime/pprof"
"strconv"
Expand Down Expand Up @@ -47,20 +46,20 @@ func (e *ErrorHandler) HandleError(w http.ResponseWriter, r *http.Request, errMs

w.Header().Set("Content-Type", contentType)

templateName := fmt.Sprintf("error_%s.%s", strconv.Itoa(errCode), templateExtension)
templateName := "error_" + strconv.Itoa(errCode) + "." + templateExtension

// Try to use an error template that matches the HTTP error code and the content type: 500.json, 400.xml, etc.
tmpl := templates.Lookup(templateName)

// Fallback to a generic error template, but match the content type: error.json, error.xml, etc.
if tmpl == nil {
templateName = fmt.Sprintf("%s.%s", defaultTemplateName, templateExtension)
templateName = defaultTemplateName + "." + templateExtension
tmpl = templates.Lookup(templateName)
}

// If no template is available for this content type, fallback to "error.json".
if tmpl == nil {
templateName = fmt.Sprintf("%s.%s", defaultTemplateName, defaultTemplateFormat)
templateName = defaultTemplateName + "." + defaultTemplateFormat
tmpl = templates.Lookup(templateName)
w.Header().Set("Content-Type", defaultContentType)
}
Expand Down
4 changes: 1 addition & 3 deletions handler_success.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (

"github.com/TykTechnologies/tyk/request"

"fmt"

"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/user"
)
Expand Down Expand Up @@ -62,7 +60,7 @@ func tagHeaders(r *http.Request, th []string, tags []string) []string {

if ok {
for _, val := range v {
tagName := fmt.Sprintf("%s-%s", cleanK, val)
tagName := cleanK + "-" + val
tags = append(tags, tagName)
}
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ func start() {
func generateListener(listenPort int) (net.Listener, error) {
listenAddress := config.Global().ListenAddress

targetPort := fmt.Sprintf("%s:%d", listenAddress, listenPort)
targetPort := listenAddress + ":" + strconv.Itoa(listenPort)

if httpServerOptions := config.Global().HttpServerOptions; httpServerOptions.UseSSL {
mainLog.Info("--> Using SSL (https)")
Expand Down Expand Up @@ -1213,7 +1213,7 @@ func listen(listener, controlListener net.Listener, err error) {
readTimeout := defReadTimeout
writeTimeout := defWriteTimeout

targetPort := fmt.Sprintf("%s:%d", config.Global().ListenAddress, config.Global().ListenPort)
targetPort := config.Global().ListenAddress + ":" + strconv.Itoa(config.Global().ListenPort)
if config.Global().HttpServerOptions.ReadTimeout > 0 {
readTimeout = time.Duration(config.Global().HttpServerOptions.ReadTimeout) * time.Second
}
Expand Down
3 changes: 1 addition & 2 deletions mw_api_rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"errors"
"fmt"
"net/http"

"strconv"
Expand Down Expand Up @@ -30,7 +29,7 @@ func (k *RateLimitForAPI) EnabledForSpec() bool {
}

// We'll init here
k.keyName = fmt.Sprintf("apilimiter-%s%s", k.Spec.OrgID, k.Spec.APIID)
k.keyName = "apilimiter-" + k.Spec.OrgID + k.Spec.APIID

// Set last updated on each load to ensure we always use a new rate limit bucket
k.apiSess = &user.SessionState{
Expand Down
14 changes: 9 additions & 5 deletions mw_url_rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func checkHeaderTrigger(r *http.Request, options map[string]apidef.StringRegexMa
for i, v := range vals {
b := mr.Check(v)
if len(b) > 0 {
kn := fmt.Sprintf("trigger-%d-%s-%d", triggernum, mhCN, i)
kn := "trigger-" + strconv.Itoa(triggernum) + "-" + mhCN + "-" + strconv.Itoa(i)
contextData[kn] = b
fCount++
}
Expand Down Expand Up @@ -382,7 +382,8 @@ func checkQueryString(r *http.Request, options map[string]apidef.StringRegexMap,
for i, v := range vals {
b := mr.Check(v)
if len(b) > 0 {
kn := fmt.Sprintf("trigger-%d-%s-%d", triggernum, mv, i)
kn := "trigger-" + strconv.Itoa(triggernum) + "-" + mv + "-" + strconv.Itoa(i)

contextData[kn] = b
fCount++
}
Expand Down Expand Up @@ -411,7 +412,8 @@ func checkPathParts(r *http.Request, options map[string]apidef.StringRegexMap, a
for _, part := range pathParts {
b := mr.Check(part)
if len(b) > 0 {
kn := fmt.Sprintf("trigger-%d-%s-%d", triggernum, mv, fCount)
kn := "trigger-" + strconv.Itoa(triggernum) + "-" + mv + "-" + strconv.Itoa(fCount)

contextData[kn] = b
fCount++
}
Expand Down Expand Up @@ -440,7 +442,8 @@ func checkSessionTrigger(r *http.Request, sess *user.SessionState, options map[s
if valOk {
b := mr.Check(val)
if len(b) > 0 {
kn := fmt.Sprintf("trigger-%d-%s", triggernum, mh)
kn := "trigger-" + strconv.Itoa(triggernum) + "-" + mh

contextData[kn] = b
fCount++
}
Expand All @@ -467,7 +470,8 @@ func checkPayload(r *http.Request, options apidef.StringRegexMap, triggernum int

b := options.Check(string(bodyBytes))
if len(b) > 0 {
kn := fmt.Sprintf("trigger-%d-payload", triggernum)
kn := "trigger-" + strconv.Itoa(triggernum) + "-payload"

contextData[kn] = string(b)
return true
}
Expand Down
2 changes: 1 addition & 1 deletion mw_validate_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (k *ValidateJSON) formatError(schemaErrors []gojsonschema.ResultError) erro
if i == 0 {
errStr = desc.String()
} else {
errStr = fmt.Sprintf("%s; %s", errStr, desc)
errStr = errStr + "; " + desc.String()
}
}

Expand Down

0 comments on commit aa1f481

Please sign in to comment.