Go

Go

Made by DeepSource

strings.HasPrefix with constant strings as arguments GO-W1022

Bug risk
Critical

There's a possible a bug-risk because of the usage of constant strings as arguments to strings.HasPrefix. It implies that the result of strings.HasPrefix is already known, and we could have avoided the usage of the function entirely. Especially, the first argument of the function is not expected to be a constant string literal.

Bad practice

s := "hello world"
if strings.HasPrefix("s", "pre") {
    // body
}

Recommended

s := "hello world"
if strings.HasPrefix(s, "pre") {
    // body
}