Documentation ¶
Overview ¶
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Package wserver provides building simple websocket server with message push.
Index ¶
Constants ¶
const (
EVENT_NEW_UNIT = "new_unit"
)
Variables ¶
var ErrRequestIllegal = errors.New("request data illegal")
ErrRequestIllegal describes error when data of the request is unaccepted.
Functions ¶
func NewEvent2Cons ¶
func NewEvent2Cons() *event2Cons
Types ¶
type BlockDbUIData ¶ added in v0.0.2
type BlockDbUIData struct {
Nodes []types.TxiSmallCaseMarshal `json:"nodes"`
}
type Conn ¶
type Conn struct { Conn *websocket.Conn AfterReadFunc func(messageType int, r io.Reader) BeforeCloseFunc func() // contains filtered or unexported fields }
Conn wraps websocket.Conn with Conn. It defines to listen and read data from Conn.
type PushMessage ¶
type PushMessage struct { //UserID string `json:"userId"` Event string `json:"event"` Message string `json:"message"` }
PushMessage defines message struct send by client to push to each connected websocket client.
type RegisterMessage ¶
type RegisterMessage struct { //Token string Event string `json:"event"` }
RegisterMessage defines message struct client send after connect to the server.
type Server ¶
type Server struct { // Address for server to listen on Addr string // Path for websocket request, default "/ws". WSPath string // Path for push message, default "/push". PushPath string // Upgrader is for upgrade connection to websocket connection using // "github.com/gorilla/websocket". // // If Upgrader is nil, default upgrader will be used. Default upgrader is // set ReadBufferSize and WriteBufferSize to 1024, and CheckOrigin always // returns true. Upgrader *websocket.Upgrader // Authorize push request. Message will be sent if it returns true, // otherwise the request will be discarded. Default nil and push request // will always be accepted. PushAuth func(r *http.Request) bool // To receive new tx events NewTxReceivedChan chan types.Txi // to receive confirmation events BatchConfirmedChan chan map[types2.Hash]types.Txi // contains filtered or unexported fields }
Server defines parameters for running websocket server.
func (*Server) GetBenchmarks ¶
func (*Server) Serve ¶
func (s *Server) Serve()
ListenAndServe listens on the TCP network address and handle websocket request.
func (*Server) WatchNewTxs ¶
func (s *Server) WatchNewTxs()