Skip to content

Commit

Permalink
Replace int-to-string casts with conversion
Browse files Browse the repository at this point in the history
The upcoming change in Go 1.15 `go vet` command disallows type casts
from `int` to `string`. This PR replaces `string(int)` conversions
with explicit formatting.

golang/go#3939
  • Loading branch information
Andrey Slotin committed May 19, 2020
1 parent a86d29d commit 52822d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions autoprofile/internal/pprof/profile/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

package profile

import "errors"
import (
"errors"
"fmt"
)

type buffer struct {
field int
Expand Down Expand Up @@ -232,7 +235,7 @@ func decodeField(b *buffer, data []byte) ([]byte, error) {
b.u64 = uint64(le32(data[:4]))
data = data[4:]
default:
return nil, errors.New("unknown type: " + string(b.typ))
return nil, fmt.Errorf("unknown type: %d", b.typ)
}

return data, nil
Expand Down
2 changes: 1 addition & 1 deletion example/autoprofile/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func leakMemory(duration int, size int) {
for j := 0; j < duration; j++ {
go func() {
for i := 0; i < size; i++ {
mem = append(mem, string(i))
mem = append(mem, strconv.Itoa(i))
}
}()

Expand Down

0 comments on commit 52822d3

Please sign in to comment.