burrow: github.com/hyperledger/burrow/rpc/lib/server Index | Files

package server

import "github.com/hyperledger/burrow/rpc/lib/server"

Commons for HTTP handling


Package Files

handlers.go http_params.go http_server.go


var (
    RE_HEX     = regexp.MustCompile(`^(?i)[a-f0-9]+$`)
    RE_EMAIL   = regexp.MustCompile(`^(?i)(` + dotAtom + `)@(` + dotAtom + `)$`)
    RE_ADDRESS = regexp.MustCompile(`^(?i)[a-z0-9]{25,34}$`)
    RE_HOST    = regexp.MustCompile(`^(?i)(` + domain + `)$`)

func EventSubscriber Uses

func EventSubscriber(eventSub types.EventSubscriber) func(*wsConnection)

EventSubscriber sets object that is used to subscribe / unsubscribe from events - not Goroutine-safe. If none given, default node's eventBus will be used.

func GetParam Uses

func GetParam(r *http.Request, param string) string

func GetParamByteSlice Uses

func GetParamByteSlice(r *http.Request, param string) ([]byte, error)

func GetParamFloat64 Uses

func GetParamFloat64(r *http.Request, param string) (float64, error)

func GetParamInt32 Uses

func GetParamInt32(r *http.Request, param string) (int32, error)

func GetParamInt64 Uses

func GetParamInt64(r *http.Request, param string) (int64, error)

func GetParamRegexp Uses

func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error)

func GetParamUint Uses

func GetParamUint(r *http.Request, param string) (uint, error)

func GetParamUint64 Uses

func GetParamUint64(r *http.Request, param string) (uint64, error)

func NewWSConnection Uses

func NewWSConnection(baseConn *websocket.Conn, funcMap map[string]*RPCFunc,
    logger *logging.Logger, options ...func(*wsConnection)) *wsConnection

NewWSConnection wraps websocket.Conn.

See the commentary on the func(*wsConnection) functions for a detailed description of how to configure ping period and pong wait time. NOTE: if the write buffer is full, pongs may be dropped, which may cause clients to disconnect. see https://github.com/gorilla/websocket/issues/97

func PingPeriod Uses

func PingPeriod(pingPeriod time.Duration) func(*wsConnection)

PingPeriod sets the duration for sending websocket pings. It should only be used in the constructor - not Goroutine-safe.

func ReadWait Uses

func ReadWait(readWait time.Duration) func(*wsConnection)

ReadWait sets the amount of time to wait before a websocket read times out. It should only be used in the constructor - not Goroutine-safe.

func RecoverAndLogHandler Uses

func RecoverAndLogHandler(handler http.Handler, logger *logging.Logger) http.Handler

Wraps an HTTP handler, adding error logging. If the inner function panics, the outer function recovers, logs, sends an HTTP 500 error response.

func RegisterRPCFuncs Uses

func RegisterRPCFuncs(mux *http.ServeMux, funcMap map[string]*RPCFunc, logger *logging.Logger)

RegisterRPCFuncs adds a route for each function in the funcMap, as well as general jsonrpc and websocket handlers for all functions. "result" is the interface on which the result objects are registered, and is popualted with every RPCResponse

func StartHTTPServer Uses

func StartHTTPServer(listener net.Listener, handler http.Handler, logger *logging.Logger) (*http.Server, error)

func WriteChanCapacity Uses

func WriteChanCapacity(cap int) func(*wsConnection)

WriteChanCapacity sets the capacity of the websocket write channel. It should only be used in the constructor - not Goroutine-safe.

func WriteRPCResponseHTTP Uses

func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse)

func WriteWait Uses

func WriteWait(writeWait time.Duration) func(*wsConnection)

WriteWait sets the amount of time to wait before a websocket write times out. It should only be used in the constructor - not Goroutine-safe.

type RPCFunc Uses

type RPCFunc struct {
    // contains filtered or unexported fields

RPCFunc contains the introspected type information for a function

func NewRPCFunc Uses

func NewRPCFunc(f interface{}, args string) *RPCFunc

NewRPCFunc wraps a function for introspection. f is the function, args are comma separated argument names

func NewWSRPCFunc Uses

func NewWSRPCFunc(f interface{}, args string) *RPCFunc

NewWSRPCFunc wraps a function for introspection and use in the websockets.

type ResponseWriterWrapper Uses

type ResponseWriterWrapper struct {
    Status int

Remember the status for logging

func (*ResponseWriterWrapper) Hijack Uses

func (w *ResponseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error)

implements http.Hijacker

func (*ResponseWriterWrapper) WriteHeader Uses

func (w *ResponseWriterWrapper) WriteHeader(status int)

type WebsocketManager Uses

type WebsocketManager struct {
    // contains filtered or unexported fields

WebsocketManager is the main manager for all websocket connections. It holds the event switch and a map of functions for routing. NOTE: The websocket path is defined externally, e.g. in node/node.go

func NewWebsocketManager Uses

func NewWebsocketManager(funcMap map[string]*RPCFunc, logger *logging.Logger,
    wsConnOptions ...func(*wsConnection)) *WebsocketManager

NewWebsocketManager returns a new WebsocketManager that routes according to the given funcMap and connects to the server with the given connection options.

func (*WebsocketManager) WebsocketHandler Uses

func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Request)

WebsocketHandler upgrades the request/response (via http.Hijack) and starts the wsConnection.

Package server imports 24 packages (graph) and is imported by 12 packages. Updated 2020-03-24. Refresh now. Tools for package owners.