From f38bfb1d16ac12df7dbc6d23c1b000964154d69e Mon Sep 17 00:00:00 2001 From: liangzai450 Date: Tue, 12 Mar 2024 00:47:07 +0800 Subject: [PATCH] =?UTF-8?q?fixbug:=20=E6=8D=A2=E8=A1=8C=E7=AC=A6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E6=95=B0=E7=BB=84=E8=B6=8A=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/events.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/service/events.go b/service/events.go index 9530940..c11266d 100644 --- a/service/events.go +++ b/service/events.go @@ -2,10 +2,11 @@ package service import ( "fmt" - "github.com/beancount-gs/script" - "github.com/gin-gonic/gin" "sort" "strings" + + "github.com/beancount-gs/script" + "github.com/gin-gonic/gin" ) type Event struct { @@ -49,6 +50,9 @@ func GetAllEvents(c *gin.Context) { } // split line by " " words := strings.Fields(line) + if len(words) < 4 { + continue + } if words[1] != "event" { continue } @@ -58,8 +62,10 @@ func GetAllEvents(c *gin.Context) { Description: strings.ReplaceAll(words[3], "\"", ""), }) } - // events 按时间倒序排列 - sort.Sort(sort.Reverse(events)) + if len(events) > 0 { + // events 按时间倒序排列 + sort.Sort(sort.Reverse(events)) + } OK(c, events) }