suggestion: "node1" + "," + "node2"
163 Action: func(cliCtx *cli.Context) error {
164 require.Equal(t, true, cliCtx.IsSet(cmd.BootstrapNode.Name))
165
166 require.Equal(t, strings.Join([]string{"node1", "node2"}, ","),167 strings.Join(cliCtx.StringSlice(cmd.BootstrapNode.Name), ","))
168 return nil
169 },
Description
Some string concatenation operations such as strings.Join
called with a single
or a two element slice can be simplified using binary operators.
This also improves performance as it doesn't need to allocate a new slice and iterate through it.
Bad practice
func foo(x, y string) string {
return strings.Join([]string{x, y}, "_")
}
Recommended
func foo(x, y string) string {
return x + "_" + y
}