The analyzer has detected a string with a potentially incorrect leading or trailing whitespace character.
Consider several examples that trigger this warning.
The example N1:
func buildRequestHeaders() {
headers := map[string]string{
"Content-Type": "application/json",
"Accept ": "application/json",
"User-Agent": "my-service/1.0",
....
}
....
}
The "Accept " string key contains a trailing whitespace character. If a value is retrieved via the "Accept" key (without the whitespace), it will not be found.
To fix the issue, remove the whitespace:
"Accept": "application/json"
The example N2:
func registerFlags() {
debug := flag.Bool("debug", false, "enable debug logging")
port := flag.Int(" port", 8080, "server port")
flag.Parse()
....
}
The " port" flag name starts with the whitespace. As a result, the flag will be registered with this exact name, and users cannot pass it in the expected way (--port).
To fix the issue, remove the whitespace:
port := flag.Int("port", 8080, "server port")
The example N3:
func decodeUser() {
type User struct {
ID int `json:"id"`
Name string `json:" name"`
}
u := User{
ID: 1,
Name: "Donald",
}
....
}
The json:" name" tag value contains a leading whitespace character. During JSON serialization and deserialization, the " name" key will be used instead of the expected "name" key.
To fix the issue, remove the whitespace:
Name string `json:"name"`
Was this page helpful?