Merge pull request #111496 from HecarimV/unnecessary-fmt

Remove unnecessary use of fmt.Sprintf
This commit is contained in:
Kubernetes Prow Robot 2022-07-28 19:35:17 -07:00 committed by GitHub
commit da0091ceda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View File

@ -27,9 +27,9 @@ func ShortHumanDuration(d time.Duration) string {
// Allow deviation no more than 2 seconds(excluded) to tolerate machine time // Allow deviation no more than 2 seconds(excluded) to tolerate machine time
// inconsistence, it can be considered as almost now. // inconsistence, it can be considered as almost now.
if seconds := int(d.Seconds()); seconds < -1 { if seconds := int(d.Seconds()); seconds < -1 {
return fmt.Sprintf("<invalid>") return "<invalid>"
} else if seconds < 0 { } else if seconds < 0 {
return fmt.Sprintf("0s") return "0s"
} else if seconds < 60 { } else if seconds < 60 {
return fmt.Sprintf("%ds", seconds) return fmt.Sprintf("%ds", seconds)
} else if minutes := int(d.Minutes()); minutes < 60 { } else if minutes := int(d.Minutes()); minutes < 60 {
@ -49,9 +49,9 @@ func HumanDuration(d time.Duration) string {
// Allow deviation no more than 2 seconds(excluded) to tolerate machine time // Allow deviation no more than 2 seconds(excluded) to tolerate machine time
// inconsistence, it can be considered as almost now. // inconsistence, it can be considered as almost now.
if seconds := int(d.Seconds()); seconds < -1 { if seconds := int(d.Seconds()); seconds < -1 {
return fmt.Sprintf("<invalid>") return "<invalid>"
} else if seconds < 0 { } else if seconds < 0 {
return fmt.Sprintf("0s") return "0s"
} else if seconds < 60*2 { } else if seconds < 60*2 {
return fmt.Sprintf("%ds", seconds) return fmt.Sprintf("%ds", seconds)
} }

View File

@ -94,7 +94,7 @@ func (u responseUpgrader) UpgradeResponse(w http.ResponseWriter, req *http.Reque
hijacker, ok := w.(http.Hijacker) hijacker, ok := w.(http.Hijacker)
if !ok { if !ok {
errorMsg := fmt.Sprintf("unable to upgrade: unable to hijack response") errorMsg := "unable to upgrade: unable to hijack response"
http.Error(w, errorMsg, http.StatusInternalServerError) http.Error(w, errorMsg, http.StatusInternalServerError)
return nil return nil
} }

View File

@ -352,8 +352,8 @@ func TestEvaluateTypes(t *testing.T) {
t.Run(fmt.Sprintf("%d_raw", i), func(t *testing.T) { t.Run(fmt.Sprintf("%d_raw", i), func(t *testing.T) {
// decode the input as a standalone object // decode the input as a standalone object
inputJSON := fmt.Sprintf(`%s`, tc.In) inputJSON := tc.In
expectedJSON := fmt.Sprintf(`%s`, tc.Out) expectedJSON := tc.Out
var m interface{} var m interface{}
err := Unmarshal([]byte(inputJSON), &m) err := Unmarshal([]byte(inputJSON), &m)
if tc.Err && err != nil { if tc.Err && err != nil {

View File

@ -142,7 +142,7 @@ func GetCaller() string {
runtime.Callers(3, pc[:]) runtime.Callers(3, pc[:])
f := runtime.FuncForPC(pc[0]) f := runtime.FuncForPC(pc[0])
if f == nil { if f == nil {
return fmt.Sprintf("Unable to find caller") return "Unable to find caller"
} }
return f.Name() return f.Name()
} }