fixbug: 换行符导致的数组越界
This commit is contained in:
parent
e382a4d0fa
commit
f38bfb1d16
|
|
@ -2,10 +2,11 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beancount-gs/script"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beancount-gs/script"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
|
|
@ -49,6 +50,9 @@ func GetAllEvents(c *gin.Context) {
|
||||||
}
|
}
|
||||||
// split line by " "
|
// split line by " "
|
||||||
words := strings.Fields(line)
|
words := strings.Fields(line)
|
||||||
|
if len(words) < 4 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if words[1] != "event" {
|
if words[1] != "event" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -58,8 +62,10 @@ func GetAllEvents(c *gin.Context) {
|
||||||
Description: strings.ReplaceAll(words[3], "\"", ""),
|
Description: strings.ReplaceAll(words[3], "\"", ""),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if len(events) > 0 {
|
||||||
// events 按时间倒序排列
|
// events 按时间倒序排列
|
||||||
sort.Sort(sort.Reverse(events))
|
sort.Sort(sort.Reverse(events))
|
||||||
|
}
|
||||||
OK(c, events)
|
OK(c, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue