github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/net/websocket/wsjson.go (about) 1 package websocket 2 3 // WSRequest means the data structure of the request 4 type WSRequest struct { 5 Topic string `json:"topic"` 6 } 7 8 // NewWSRequest creates a request data object 9 func NewWSRequest(topic string) *WSRequest { 10 return &WSRequest{ 11 Topic: topic, 12 } 13 } 14 15 // WSResponse means the returned data structure 16 type WSResponse struct { 17 NotificationType string `json:"notification_type"` 18 Data interface{} `json:"data"` 19 ErrorDetail string `json:"error_detail,omitempty"` 20 } 21 22 // NewWSResponse creates a return data object 23 func NewWSResponse(notificationType string, data interface{}, err error) *WSResponse { 24 wsResp := &WSResponse{ 25 NotificationType: notificationType, 26 Data: data, 27 } 28 29 if err != nil { 30 wsResp.ErrorDetail = err.Error() 31 } 32 33 return wsResp 34 }