fmt.Sprintf("%s", x)
unnecessarily SCC-S102515// Error makes it compatible with `error` interface
16func (he *HTTPError) Error() string {
17 if he.Internal == nil {
18 return fmt.Sprintf("%s", he.Message)19 }
20 return fmt.Sprintf("%s: %s", he.Message, he.Internal)
21}
There are more accessible and efficient ways of getting a value's string
representation in many instances. Whenever a value's underlying type is a
string
already, or the type has a String()
method, they should be used
directly.
Given the following shared definitions:
type T1 string
type T2 int
func (T2) String() string { return "Hello, world" }
var x string
var y T1
var z T2
fmt.Sprintf("%s", x)
fmt.Sprintf("%s", y)
fmt.Sprintf("%s", z)
x
string(y)
z.String()