本文整理汇总了Golang中github.com/sarifsystems/sarif/sarif.Message.IsAction方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.IsAction方法的具体用法?Golang Message.IsAction怎么用?Golang Message.IsAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/sarifsystems/sarif/sarif.Message
的用法示例。
在下文中一共展示了Message.IsAction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleCounter
func (s *Service) handleCounter(msg sarif.Message) {
if msg.Text == "" {
s.ReplyBadRequest(msg, errors.New("Please specify a counter name!"))
return
}
name := msg.Text
cnt, err := s.counterGet(name)
if err != nil {
s.ReplyInternalError(msg, err)
return
}
newCnt := cnt
if msg.IsAction("cmd/decrement") {
newCnt--
} else if msg.IsAction("cmd/increment") {
newCnt++
}
if newCnt != cnt {
if err := s.counterSet(name, newCnt); err != nil {
s.ReplyInternalError(msg, err)
return
}
}
s.Reply(msg, sarif.CreateMessage("counter/changed/"+name, &counterMessage{name, newCnt}))
}
示例2: clientIsAllowed
func (s *Server) clientIsAllowed(client string, msg sarif.Message) bool {
allowed, ok := s.cfg.AllowedActions[client]
if !ok {
return true
}
for _, action := range allowed {
if msg.IsAction(action) {
return true
}
}
return false
}
示例3: checkErr
func checkErr(reply sarif.Message, ok bool) error {
if !ok {
return ErrNoReply
}
if reply.IsAction("err/notfound") {
return ErrNotFound
}
if reply.IsAction("err") {
return errors.New(reply.Text)
}
return nil
}
示例4: handleQuestionAnswer
func (s *Service) handleQuestionAnswer(msg sarif.Message) {
if msg.IsAction("question/answer/ultimate") {
reply := "Wrong. The answer is 42."
if msg.Text == "42" {
reply = "Precisely."
}
s.Reply(msg, sarif.Message{
Action: "question/accepted",
Text: reply,
})
return
}
s.Reply(msg, sarif.Message{
Action: "err/question/unknown",
Text: "I can't remember asking you a question.",
})
}
示例5: handleLog
func (s *Service) handleLog(msg sarif.Message) {
targets := make(map[string]struct{})
for action, target := range s.Cfg.Actions {
if msg.IsAction(action) {
targets[target] = struct{}{}
}
}
lm := LogMessage{time.Now(), msg}
s.mutex.Lock()
defer s.mutex.Unlock()
for target := range targets {
if target == "" {
continue
}
raw, _ := json.Marshal(lm)
if err := s.writeTarget(target, string(raw)); err != nil {
log.Println("[log] write error:", err)
}
}
}
示例6: handleEventNew
func (s *Service) handleEventNew(msg sarif.Message) {
isTargeted := msg.IsAction("event/new")
var e Event
e.Text = msg.Text
e.Time = time.Now()
e.Value = 1
if s, v, ok := parseDataFromAction(msg.Action, "event/new"); ok {
e.Action, e.Value = s, v
}
if err := msg.DecodePayload(&e); err != nil && isTargeted {
s.ReplyBadRequest(msg, err)
return
}
if err := msg.DecodePayload(&e.Meta); err != nil {
s.ReplyBadRequest(msg, err)
return
}
if e.Time.IsZero() {
e.Time = time.Now()
}
if _, err := s.Store.Put(e.Key(), &e); err != nil {
s.Log("err/internal", "could not store finished task: "+err.Error())
return
}
if isTargeted {
reply := sarif.Message{Action: "event/created"}
if err := reply.EncodePayload(e); err != nil {
s.ReplyInternalError(msg, err)
return
}
reply.Text = "New event: " + e.String()
s.Reply(msg, reply)
}
}