mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
enhance(nginx-log): do not seek file if it size is 0 #674
This commit is contained in:
parent
b552973998
commit
cb5c64dec4
1 changed files with 10 additions and 5 deletions
|
@ -49,7 +49,6 @@ func GetNginxLogPage(c *gin.Context) {
|
|||
}
|
||||
|
||||
logPath, err := getLogPath(&control)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nginxLogPageResp{
|
||||
Error: err.Error(),
|
||||
|
@ -59,7 +58,6 @@ func GetNginxLogPage(c *gin.Context) {
|
|||
}
|
||||
|
||||
logFileStat, err := os.Stat(logPath)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nginxLogPageResp{
|
||||
Error: err.Error(),
|
||||
|
@ -76,8 +74,16 @@ func GetNginxLogPage(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
f, err := os.Open(logPath)
|
||||
// to fix: seek invalid argument #674
|
||||
if logFileStat.Size() == 0 {
|
||||
c.JSON(http.StatusOK, nginxLogPageResp{
|
||||
Page: 1,
|
||||
Content: "",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
f, err := os.Open(logPath)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nginxLogPageResp{
|
||||
Error: err.Error(),
|
||||
|
@ -112,8 +118,7 @@ func GetNginxLogPage(c *gin.Context) {
|
|||
}
|
||||
|
||||
n, err := f.Read(buf)
|
||||
|
||||
if err != nil && err != io.EOF {
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
c.JSON(http.StatusInternalServerError, nginxLogPageResp{
|
||||
Error: err.Error(),
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue