Skip to content

Commit

Permalink
PMM-13054 Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Jun 17, 2024
1 parent a381f0f commit d6c02e0
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions managed/services/supervisord/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ func (l *Logs) victoriaMetricsTargets(ctx context.Context) ([]byte, error) {
// and returns them together with modification time.
func readLog(name string, readLines int) ([]byte, time.Time, error) {
var (
m time.Time
res []byte
maxLines int
m time.Time
res []byte
lineCount int
)
f, err := os.Open(name)
f, err := os.Open(name) //nolint:gosec
if err != nil {
return nil, m, errors.WithStack(err)
}
defer f.Close() //nolint:gosec,errcheck
defer f.Close() //nolint:errcheck

fi, err := f.Stat()
if err != nil {
Expand All @@ -291,17 +291,17 @@ func readLog(name string, readLines int) ([]byte, time.Time, error) {
switch readLines {
case 0:
// no parameter passed, use the default line count
maxLines = maxLogReadLines
res = make([]byte, maxLines)
lineCount = maxLogReadLines
case -1:
// unlimited number of lines
default:
maxLines = readLines
res = make([]byte, maxLines)
lineCount = readLines
}

res = make([]byte, 0)

Check failure on line 301 in managed/services/supervisord/logs.go

View workflow job for this annotation

GitHub Actions / Checks

empty slice: use []T{}

reader := bufio.NewReader(f)
for maxLines >= 0 {
for lineCount >= 0 {
b, err := reader.ReadBytes('\n')
if err == io.EOF {
// A special case when the last line does not end with a new line
Expand All @@ -318,7 +318,8 @@ func readLog(name string, readLines int) ([]byte, time.Time, error) {
}

if readLines != -1 {
maxLines--
// Do not decrease the counter for unlimited line count
lineCount--
}
}

Expand Down

0 comments on commit d6c02e0

Please sign in to comment.