enhance(nginx-log): do not seek file if it size is 0 #674

This commit is contained in:
Jacky 2024-11-04 10:54:18 +08:00
parent b552973998
commit cb5c64dec4
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D

View file

@ -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(),
})