|
@@ -2,23 +2,35 @@ package pubsub
|
|
|
|
|
|
import "encoding/json"
|
|
|
|
|
|
-type Response struct {
|
|
|
- Type string `json:"type"`
|
|
|
+type AnswerType string
|
|
|
+
|
|
|
+const (
|
|
|
+ Listen AnswerType = "LISTEN"
|
|
|
+ Message AnswerType = "MESSAGE"
|
|
|
+ Ping AnswerType = "PING"
|
|
|
+ Pong AnswerType = "PONG"
|
|
|
+ Reconnect AnswerType = "RECONNECT"
|
|
|
+ Response AnswerType = "RESPONSE"
|
|
|
+ Unlisten AnswerType = "UNLISTEN"
|
|
|
+)
|
|
|
+
|
|
|
+type Answer struct {
|
|
|
+ Type AnswerType `json:"type"`
|
|
|
Data interface{} `json:"data,omitempty"`
|
|
|
Error string `json:"error,omitempty"`
|
|
|
Nonce string `json:"nonce,omitempty"`
|
|
|
}
|
|
|
|
|
|
-func (r Response) JSON() []byte {
|
|
|
+func (r Answer) JSON() []byte {
|
|
|
bytes, _ := json.Marshal(r)
|
|
|
return bytes
|
|
|
}
|
|
|
|
|
|
-type DataTopics struct {
|
|
|
+type AnswerDataTopics struct {
|
|
|
Topics []string `json:"topics"`
|
|
|
}
|
|
|
|
|
|
-func (d DataTopics) JSON() []byte {
|
|
|
+func (d AnswerDataTopics) JSON() []byte {
|
|
|
bytes, _ := json.Marshal(d)
|
|
|
return bytes
|
|
|
}
|