master
ehlxr 2019-12-16 18:28:18 +08:00
parent 2574de9a2f
commit 72e5c0f6ad
1 changed files with 7 additions and 6 deletions

13
main.go
View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"strings" "strings"
"time" "time"
@ -37,12 +36,15 @@ func main() {
} }
func sendMsg(content string) { func sendMsg(content string) {
if err := dingTalk.SendTextMessage( if err := dingTalk.SendMarkdownMessage(
"new message",
fmt.Sprintf("%s\n%s", pkg.Opts.AppName, content), fmt.Sprintf("%s\n%s", pkg.Opts.AppName, content),
pkg.Opts.Robot.AtMobiles, pkg.Opts.Robot.AtMobiles,
pkg.Opts.Robot.IsAtAll, pkg.Opts.Robot.IsAtAll,
); err != nil { ); err != nil {
log.Error("%+v", err) log.Error("%+v", err)
return
} }
log.Info("send message <%s> success", content) log.Info("send message <%s> success", content)
@ -69,7 +71,7 @@ func tailFile() {
pkg.Opts.KeyWord, pkg.Opts.KeyWord,
pkg.Opts.KeyWordIgnoreCase) pkg.Opts.KeyWordIgnoreCase)
var buffer bytes.Buffer var buffer strings.Builder
var times int var times int
go func() { go func() {
ticker := time.NewTicker(1 * time.Minute) ticker := time.NewTicker(1 * time.Minute)
@ -80,6 +82,7 @@ func tailFile() {
buffer.Reset() buffer.Reset()
} }
buffer.Reset()
times = 0 times = 0
} }
}() }()
@ -99,9 +102,7 @@ func tailFile() {
// log.Error("dingTalk 1 m allow send 20 msg. msg %v discarded.", // log.Error("dingTalk 1 m allow send 20 msg. msg %v discarded.",
// line.Text) // line.Text)
//} //}
buffer.WriteString("- " + line.Text + "\n")
buffer.WriteString(line.Text)
buffer.WriteByte('\n')
times++ times++
break break