forked from priscillachat/priscilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.go
41 lines (37 loc) · 1.07 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"errors"
)
type query struct {
Type string `json:"type"`
Source string `json:"source"`
To string `json:"to"`
Command *commandBlock `json:"command"`
Message *messageBlock `json:"message"`
}
func (q *query) validate() error {
switch {
case q.Type == "command" && q.Command == nil:
return errors.New("Missing command block")
case q.Type == "message" && q.Message == nil:
return errors.New("Missing message block")
case q.Type != "command" && q.Type != "message":
return errors.New("Invalid query type")
default:
return nil
}
}
func (q *query) checkEngagement() error {
switch {
case q.Type != "command":
return errors.New("Invalid query type for engegement: " + q.Type)
case q.Command == nil:
return errors.New("Empty command block")
case q.Command.Action != "engage":
return errors.New("First command is not engagement: " + q.Command.Action)
case q.Command.Type != "adapter" && q.Command.Type != "responder":
return errors.New("Unsupported engagement type: " + q.Command.Type)
default:
return nil
}
}