OSDN Git Service

Hulk did something
[bytom/vapor.git] / net / websocket / wsjson.go
diff --git a/net/websocket/wsjson.go b/net/websocket/wsjson.go
new file mode 100644 (file)
index 0000000..5515be0
--- /dev/null
@@ -0,0 +1,34 @@
+package websocket
+
+// WSRequest means the data structure of the request
+type WSRequest struct {
+       Topic string `json:"topic"`
+}
+
+// NewWSRequest creates a request data object
+func NewWSRequest(topic string) *WSRequest {
+       return &WSRequest{
+               Topic: topic,
+       }
+}
+
+// WSResponse means the returned data structure
+type WSResponse struct {
+       NotificationType string      `json:"notification_type"`
+       Data             interface{} `json:"data"`
+       ErrorDetail      string      `json:"error_detail,omitempty"`
+}
+
+// NewWSResponse creates a return data object
+func NewWSResponse(notificationType string, data interface{}, err error) *WSResponse {
+       wsResp := &WSResponse{
+               NotificationType: notificationType,
+               Data:             data,
+       }
+
+       if err != nil {
+               wsResp.ErrorDetail = err.Error()
+       }
+
+       return wsResp
+}