suggestion: m + ": " + errMsg
302 m := parseMsg("", msg...)
303 errMsg := fmt.Sprintf("empty/zero field: %s", strings.Join(fields, "."))
304 if len(m) > 0 {
305 m = strings.Join([]string{m, errMsg}, ": ")306 } else {
307 m = errMsg
308 }
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
}