websocket

package
v0.0.0-...-f5ca578 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2022 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ok

func Ok(w http.ResponseWriter)

Ok writes HTTP 200 OK into w.

func OkJson

func OkJson(w http.ResponseWriter, v interface{})

OkJson writes v into w with 200 OK.

func Parse

func Parse(m *MessageHandler, v interface{}) error

Parse parses the request.

func ParseJsonBody

func ParseJsonBody(r *http.Request, v interface{}) error

ParseJsonBody parses the post request which contains json in body.

func ParsePath

func ParsePath(r *http.Request, v interface{}) error

ParsePath parses the symbols reside in url path. Like http://localhost/bag/:name

func RegisterWsHandlers

func RegisterWsHandlers(svcCtx *svc.ServiceContext) map[string]WsHandleFunc

func RegisterWsUpgrade

func RegisterWsUpgrade(server *rest.Server, serverCtx *svc.ServiceContext)

func SetErrorHandler

func SetErrorHandler(handler func(error) (int, interface{}))

SetErrorHandler sets the error handler, which is called on calling Error.

func WriteJson

func WriteJson(w http.ResponseWriter, code int, v interface{})

WriteJson writes v as json string into w with code.

func WsUpgradeHandler

func WsUpgradeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc

Types

type Error

type Error struct {
	ID    int    `json:"id"`
	Error Object `json:"error"`
}

type MessageHandler

type MessageHandler struct {
	// contains filtered or unexported fields
}

func NewMessageHandler

func NewMessageHandler(conn io.ReadWriteCloser, message []byte, op ws.OpCode) MessageHandler

func (*MessageHandler) Context

func (m *MessageHandler) Context() context.Context

func (*MessageHandler) Error

func (m *MessageHandler) Error(err error)

func (*MessageHandler) HandleMessage

func (m *MessageHandler) HandleMessage()

type Object

type Object map[string]interface{}

Object represents generic message parameters. In real-world application it is better to avoid such types for better performance.

type Request

type Request struct {
	ID     int    `json:"id"`
	Method string `json:"method"`
	Params Object `json:"params"`
}

type Response

type Response struct {
	ID     int    `json:"id"`
	Result Object `json:"result"`
}

type WsHandleFunc

type WsHandleFunc func(*MessageHandler)

func GetAllUsersHandler

func GetAllUsersHandler(svcCtx *svc.ServiceContext) WsHandleFunc

func PingHandler

func PingHandler(svcCtx *svc.ServiceContext) WsHandleFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL