rpcserver

package
v0.10.0-rc2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Commons for HTTP handling

Index

Constants

This section is empty.

Variables

View Source
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 + `)$`)
)

Functions

func GetParam

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

func GetParamByteSlice

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

func GetParamFloat64

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

func GetParamInt32

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

func GetParamInt64

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

func GetParamRegexp

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

func GetParamUint

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

func GetParamUint64

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

func NewWSConnection

func NewWSConnection(baseConn *websocket.Conn, funcMap map[string]*RPCFunc, evsw events.EventSwitch) *wsConnection

new websocket connection wrapper

func RecoverAndLogHandler

func RecoverAndLogHandler(handler http.Handler, logger log.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

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

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

func StartHTTPServer(listenAddr string, handler http.Handler, logger log.Logger) (listener net.Listener, err error)

func WriteRPCResponseHTTP

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

func WriteRPCResponseHTTPError

func WriteRPCResponseHTTPError(w http.ResponseWriter, httpCode int, res types.RPCResponse)

Types

type RPCFunc

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

holds all type information for each function

func NewRPCFunc

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

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

func NewWSRPCFunc

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

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	Status int
	http.ResponseWriter
}

Remember the status for logging

func (*ResponseWriterWrapper) Hijack

implements http.Hijacker

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(status int)

type WebsocketManager

type WebsocketManager struct {
	websocket.Upgrader
	// contains filtered or unexported fields
}

Main manager for all websocket connections Holds the event switch NOTE: The websocket path is defined externally, e.g. in node/node.go

func NewWebsocketManager

func NewWebsocketManager(funcMap map[string]*RPCFunc, evsw events.EventSwitch) *WebsocketManager

func (*WebsocketManager) SetLogger

func (wm *WebsocketManager) SetLogger(l log.Logger)

func (*WebsocketManager) WebsocketHandler

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

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

Jump to

Keyboard shortcuts

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