From 3962f8adc6a2c158523c200145ce12a736fcaa3c Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Wed, 26 Apr 2017 17:00:28 +1000 Subject: [PATCH] more than 8 articles will be dropped --- outMsg.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/outMsg.go b/outMsg.go index 044484d..bfdd851 100644 --- a/outMsg.go +++ b/outMsg.go @@ -150,17 +150,17 @@ func musicMsgTemplate() string { } func buildNewsMsg(ToUserName, title, description string, articles []Article) (msg string) { - count := len(articles) - if count <= 0 { - log.Fatal("using empty article to build NewsMsg") - msg = "" - return - } - + count := 0 items := []string{} for _, a := range articles { + if count >= 8 { + err := errors.New("too many articles, only take first 8") + log.Fatal(err) + break + } s := buildArticleItem(a) items = append(items, s) + count++ } strItems := strings.Join(items, "")