Added some godocs to a few websocket related structs (#13451)

* Added some godocs to a few websocket related structs

* Incoporate review comments

* Fix more review comments
Этот коммит содержится в:
Agniva De Sarker
2019-12-24 19:21:03 +05:30
коммит произвёл Joram Wilander
родитель 80dd2915db
Коммит f2a14ae976
3 изменённых файлов: 23 добавлений и 17 удалений

Просмотреть файл

@@ -17,17 +17,19 @@ const (
PING_TIMEOUT_BUFFER_SECONDS = 5
)
// WebSocketClient stores the necessary information required to
// communicate with a WebSocket endpoint.
type WebSocketClient struct {
Url string // The location of the server like "ws://localhost:8065"
ApiUrl string // The api location of the server like "ws://localhost:8065/api/v3"
ConnectUrl string // The websocket URL to connect to like "ws://localhost:8065/api/v3/path/to/websocket"
Conn *websocket.Conn // The WebSocket connection
AuthToken string // The token used to open the WebSocket
Sequence int64 // The ever-incrementing sequence attached to each WebSocket action
PingTimeoutChannel chan bool // The channel used to signal ping timeouts
EventChannel chan *WebSocketEvent
ResponseChannel chan *WebSocketResponse
ListenError *AppError
Url string // The location of the server like "ws://localhost:8065"
ApiUrl string // The API location of the server like "ws://localhost:8065/api/v3"
ConnectUrl string // The WebSocket URL to connect to like "ws://localhost:8065/api/v3/path/to/websocket"
Conn *websocket.Conn // The WebSocket connection
AuthToken string // The token used to open the WebSocket connection
Sequence int64 // The ever-incrementing sequence attached to each WebSocket action
PingTimeoutChannel chan bool // The channel used to signal ping timeouts
EventChannel chan *WebSocketEvent // The channel used to receive various events pushed from the server. For example: typing, posted
ResponseChannel chan *WebSocketResponse // The channel used to receive responses for requests made to the server
ListenError *AppError // A field that is set if there was an abnormal closure of the WebSocket connection
pingTimeoutTimer *time.Timer
}

Просмотреть файл

@@ -199,11 +199,14 @@ func WebSocketEventFromJson(data io.Reader) *WebSocketEvent {
return &ev
}
// WebSocketResponse represents a response received through the WebSocket
// for a request made to the server. This is available through the ResponseChannel
// channel in WebSocketClient.
type WebSocketResponse struct {
Status string `json:"status"`
SeqReply int64 `json:"seq_reply,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
Error *AppError `json:"error,omitempty"`
Status string `json:"status"` // The status of the response. For example: OK, FAIL.
SeqReply int64 `json:"seq_reply,omitempty"` // A counter which is incremented for every response sent.
Data map[string]interface{} `json:"data,omitempty"` // The data contained in the response.
Error *AppError `json:"error,omitempty"` // A field that is set if any error has occurred.
}
func (m *WebSocketResponse) Add(key string, value interface{}) {

Просмотреть файл

@@ -10,11 +10,12 @@ import (
goi18n "github.com/mattermost/go-i18n/i18n"
)
// WebSocketRequest represents a request made to the server through a websocket.
type WebSocketRequest struct {
// Client-provided fields
Seq int64 `json:"seq"`
Action string `json:"action"`
Data map[string]interface{} `json:"data"`
Seq int64 `json:"seq"` // A counter which is incremented for every request made.
Action string `json:"action"` // The action to perform for a request. For example: get_statuses, user_typing.
Data map[string]interface{} `json:"data"` // The metadata for an action.
// Server-provided fields
Session Session `json:"-"`