mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-16 18:54:43 +08:00
fix: 解决网站日志查看报错的问题 (#4082)
Refs https://github.com/1Panel-dev/1Panel/issues/3789
This commit is contained in:
parent
a99f19471b
commit
703da8a09a
@ -3,6 +3,7 @@ package files
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
@ -87,16 +88,20 @@ func ReadFileByLine(filename string, page, pageSize int) ([]string, bool, error)
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
reader := bufio.NewReaderSize(file, 8192)
|
||||||
|
|
||||||
var lines []string
|
var lines []string
|
||||||
currentLine := 0
|
currentLine := 0
|
||||||
startLine := (page - 1) * pageSize
|
startLine := (page - 1) * pageSize
|
||||||
endLine := startLine + pageSize
|
endLine := startLine + pageSize
|
||||||
|
|
||||||
for scanner.Scan() {
|
for {
|
||||||
|
line, _, err := reader.ReadLine()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
if currentLine >= startLine && currentLine < endLine {
|
if currentLine >= startLine && currentLine < endLine {
|
||||||
lines = append(lines, scanner.Text())
|
lines = append(lines, string(line))
|
||||||
}
|
}
|
||||||
currentLine++
|
currentLine++
|
||||||
if currentLine >= endLine {
|
if currentLine >= endLine {
|
||||||
@ -104,10 +109,6 @@ func ReadFileByLine(filename string, page, pageSize int) ([]string, bool, error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
isEndOfFile := currentLine < endLine
|
isEndOfFile := currentLine < endLine
|
||||||
|
|
||||||
return lines, isEndOfFile, nil
|
return lines, isEndOfFile, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user