Skip to content

Commit

Permalink
Remove unnecessary uses of fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed Feb 27, 2017
1 parent cfb0a5c commit a49b242
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 40 deletions.
9 changes: 0 additions & 9 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -1283,14 +1282,6 @@ func resetHandler(w http.ResponseWriter, r *http.Request) {
DoJSONWrite(w, code, responseMessage)
}

func expandKey(orgID, key string) string {
if orgID == "" {
return fmt.Sprintf("%s", key)
}

return fmt.Sprintf("%s%s", orgID, key)
}

func createKeyHandler(w http.ResponseWriter, r *http.Request) {
var responseMessage []byte
code := 200
Expand Down
3 changes: 1 addition & 2 deletions api_loader.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"net/http"
"net/url"
"sort"
Expand Down Expand Up @@ -511,7 +510,7 @@ func processSpec(referenceSpec *APISpec,

simpleChain := alice.New(fullSimpleChain...).Then(userCheckHandler)

rateLimitPath := fmt.Sprintf("%s%s", referenceSpec.Proxy.ListenPath, "tyk/rate-limits/")
rateLimitPath := referenceSpec.Proxy.ListenPath + "tyk/rate-limits/"
log.WithFields(logrus.Fields{
"prefix": "main",
"api_name": referenceSpec.APIDefinition.Name,
Expand Down
4 changes: 1 addition & 3 deletions auth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ type DefaultKeyGenerator struct {
func (b *DefaultKeyGenerator) GenerateAuthKey(OrgID string) string {
u5, _ := uuid.NewV4()
cleanSting := strings.Replace(u5.String(), "-", "", -1)
newAuthKey := expandKey(OrgID, cleanSting)

return newAuthKey
return OrgID + cleanSting
}

// GenerateHMACSecret is a utility function for generating new auth keys. Returns the storage key name and the actual key
Expand Down
26 changes: 14 additions & 12 deletions handler_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type ErrorHandler struct {
}

// HandleError is the actual error handler and will store the error details in analytics if analytics processing is enabled.
func (e *ErrorHandler) HandleError(w http.ResponseWriter, r *http.Request, err string, errCode int) {
func (e *ErrorHandler) HandleError(w http.ResponseWriter, r *http.Request, errMsg string, errCode int) {
var templateExtension string
var contentType string

Expand Down Expand Up @@ -70,7 +70,7 @@ func (e *ErrorHandler) HandleError(w http.ResponseWriter, r *http.Request, err s
// Need to return the correct error code!
w.WriteHeader(errCode)

apiError := APIError{fmt.Sprintf("%s", err)}
apiError := APIError{errMsg}
tmpl.Execute(w, &apiError)

if doMemoryProfile {
Expand Down Expand Up @@ -219,24 +219,26 @@ func (e *ErrorHandler) HandleError(w http.ResponseWriter, r *http.Request, err s
}

var ip string
if clientIP, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {
clientIP, _, err := net.SplitHostPort(r.RemoteAddr)
if err == nil {
// If we aren't the first proxy retain prior
// X-Forwarded-For information as a comma+space
// separated list and fold multiple headers into one.
if prior, ok := r.Header["X-Forwarded-For"]; ok {
clientIP = strings.Join(prior, ", ") + ", " + clientIP
}
ip = clientIP
} else {
log.WithFields(logrus.Fields{
"prefix": "gateway",
"user_ip": ip,
"server_name": e.Spec.APIDefinition.Proxy.TargetURL,
"user_id": obfuscated,
"org_id": e.Spec.APIDefinition.OrgID,
"api_id": e.Spec.APIDefinition.APIID,
"path": r.URL.Path,
}).Error("request error: ", err)
}
log.WithFields(logrus.Fields{
"prefix": "gateway",
"user_ip": ip,
"server_name": e.Spec.APIDefinition.Proxy.TargetURL,
"user_id": obfuscated,
"org_id": e.Spec.APIDefinition.OrgID,
"api_id": e.Spec.APIDefinition.APIID,
"path": r.URL.Path,
}).Error("request error: ", err)

if doMemoryProfile {
pprof.WriteHeapProfile(profileFile)
Expand Down
3 changes: 1 addition & 2 deletions instrumentation_handlers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"net/http"
"os"
"runtime/debug"
Expand Down Expand Up @@ -51,7 +50,7 @@ func InstrumentationMW(handler http.HandlerFunc) http.HandlerFunc {

handler(w, r)
job.EventKv("called", health.Kvs{
"from_ip": fmt.Sprint(r.RemoteAddr),
"from_ip": r.RemoteAddr,
"method": r.Method,
"endpoint": r.URL.Path,
"raw_url": r.URL.String(),
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ func initialiseSystem(arguments map[string]interface{}) {
if value != nil {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Debug(fmt.Sprintf("Using %s for configuration", value.(string)))
}).Debugf("Using %s for configuration", value.(string))
filename = arguments["--conf"].(string)
} else {
log.WithFields(logrus.Fields{
Expand Down
3 changes: 1 addition & 2 deletions middleware.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -58,7 +57,7 @@ func CreateMiddleware(mw TykMiddlewareImplementation, tykMwSuper *TykMiddleware)
handler := func(w http.ResponseWriter, r *http.Request) {
job := instrument.NewJob("MiddlewareCall")
meta := health.Kvs{
"from_ip": fmt.Sprint(r.RemoteAddr),
"from_ip": r.RemoteAddr,
"method": r.Method,
"endpoint": r.URL.Path,
"raw_url": r.URL.String(),
Expand Down
3 changes: 1 addition & 2 deletions plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -309,7 +308,7 @@ func (j *JSVM) LoadTykJSApi() {

u, _ := url.ParseRequestURI(domain)
u.Path = HRO.Resource
urlStr := fmt.Sprintf("%v", u) // "https://api.com/user/"
urlStr := u.String() // "https://api.com/user/"

client := &http.Client{}

Expand Down
5 changes: 2 additions & 3 deletions redis_signal_handle_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"syscall"
"time"
Expand Down Expand Up @@ -41,7 +40,7 @@ func WriteNewConfiguration(payload ConfigPayload) error {
if value != nil {
log.WithFields(logrus.Fields{
"prefix": "pub-sub",
}).Info(fmt.Sprintf("Using %s for configuration", value.(string)))
}).Infof("Using %s for configuration", value.(string))
filename = argumentsBackup["--conf"].(string)
} else {
log.WithFields(logrus.Fields{
Expand All @@ -59,7 +58,7 @@ func GetExistingRawConfig() Config {
if value != nil {
log.WithFields(logrus.Fields{
"prefix": "pub-sub",
}).Info(fmt.Sprintf("Using %s for configuration", value.(string)))
}).Infof("Using %s for configuration", value.(string))
filename = argumentsBackup["--conf"].(string)
} else {
log.WithFields(logrus.Fields{
Expand Down
3 changes: 1 addition & 2 deletions redis_signal_handle_config_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"time"

Expand Down Expand Up @@ -49,7 +48,7 @@ func GetExistingConfig() (MicroConfig, error) {
if value != nil {
log.WithFields(logrus.Fields{
"prefix": "pub-sub",
}).Info(fmt.Sprintf("Using %s for configuration", value.(string)))
}).Infof("Using %s for configuration", value.(string))
filename = argumentsBackup["--conf"].(string)
} else {
log.WithFields(logrus.Fields{
Expand Down
3 changes: 1 addition & 2 deletions rpc_backup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"net/http"
"strings"
Expand Down Expand Up @@ -185,7 +184,7 @@ func decrypt(key []byte, cryptoText string) string {
// XORKeyStream can work in-place if the two arguments are the same.
stream.XORKeyStream(ciphertext, ciphertext)

return fmt.Sprintf("%s", ciphertext)
return string(ciphertext)
}

func rightPad2Len(s, padStr string, overallLen int) string {
Expand Down

0 comments on commit a49b242

Please sign in to comment.