Skip to content

Commit

Permalink
backward compatible strings.Cut
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Jun 26, 2023
1 parent ca87d80 commit a3b0f42
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,18 @@ func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net
return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, max)
}

// strings.Cut is only available from Go 1.18 and onwards, `stringsCut` is an implementation of it
// working on older Go versions
func stringsCut(s, sep string) (string, string, bool) {
if i := strings.Index(s, sep); i >= 0 {
return s[:i], s[i+len(sep):], true
}
return s, "", false
}

// function of parsing a block
func readBlock(line string, m *MemoryMapsStat) error {
name, value, found := strings.Cut(line, ":")
name, value, found := stringsCut(line, ":")
if !found {
return nil
}
Expand Down

0 comments on commit a3b0f42

Please sign in to comment.