Skip to content

Commit

Permalink
Use fmt.Sprintf instead of a type switch to convert to string
Browse files Browse the repository at this point in the history
The `%v` format string will do the right thing when the `max_in_flight`
value is either a string or an integer.

(of course, this just moves the type switch into the standard library)

[#185483613]

Authored-by: Chris Selzo <[email protected]>
  • Loading branch information
selzoc committed Jul 5, 2023
1 parent c13b006 commit 85dafdd
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions cmd/create_recovery_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"sort"
"strconv"

"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -120,23 +119,12 @@ func (c CreateRecoveryPlanCmd) getMaxInFlightByInstanceGroup() (map[string]strin
if groupMaxInFlight == nil {
groupMaxInFlight = globalMaxInFlight
}
flightMap[instanceGroup.Name] = ensureString(groupMaxInFlight)
flightMap[instanceGroup.Name] = fmt.Sprintf("%v", groupMaxInFlight)
}

return flightMap, nil
}

func ensureString(i interface{}) string {
switch v := i.(type) {
case int:
return strconv.Itoa(v)
case string:
return v
}

return i.(string)
}

func sortedInstanceGroups(problemsByInstanceGroup map[string][]boshdir.Problem) []string {
var instanceGroups []string
for k := range problemsByInstanceGroup {
Expand Down

0 comments on commit 85dafdd

Please sign in to comment.