package support import ( "message-demo/message" "errors" "fmt" "log" ) type Support struct { Name string } // Run Cron执行 func (s Support) Run() { log.Printf("[support] 开始执行") err := errors.New("test") err = nil if err != nil { log.Printf(err.Error()) sendMessageError(s.Name, err) } else { sendSuccess(s.Name) } } // sendMessageError 发送错误信息 func sendMessageError(name string, err error) { var body = message.MessageBody{} body.Title = "签到失败" body.Content = fmt.Sprintf("%s,签到失败,错误信息: 【%s】", name, err.Error()) send(body) } // sendSuccess 签到成功 func sendSuccess(name string) { body := message.MessageBody{ Title: "签到成功", Content: name + ",签到成功", } send(body) } // send 发送 func send(body message.MessageBody) { m := message.GetSupport() if m == nil { return } enabled := message.Enabled() if enabled { m.Send(body) } }