Documentation ¶
Overview ¶
Commons for HTTP handling
Index ¶
- Variables
- func GetParam(r *http.Request, param string) string
- func GetParamByteSlice(r *http.Request, param string) ([]byte, error)
- func GetParamFloat64(r *http.Request, param string) (float64, error)
- func GetParamInt32(r *http.Request, param string) (int32, error)
- func GetParamInt64(r *http.Request, param string) (int64, error)
- func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error)
- func GetParamUint(r *http.Request, param string) (uint, error)
- func GetParamUint64(r *http.Request, param string) (uint64, error)
- func Recover(daemonName string)
- func RecoverAndLogHandler(handler http.Handler) http.Handler
- func RegisterRPCFuncs(mux *http.ServeMux, funcMap map[string]*RPCFunc)
- func StartHTTPServer(listenAddr string, handler http.Handler) (net.Listener, error)
- func WriteRPCResponse(w http.ResponseWriter, res RPCResponse)
- type RPCFunc
- type ResponseWriterWrapper
- type WSConnection
- type WebsocketManager
Constants ¶
This section is empty.
Variables ¶
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 GetParamRegexp ¶
func Recover ¶
func Recover(daemonName string)
Stick it as a deferred statement in gouroutines to prevent the program from crashing.
func RecoverAndLogHandler ¶
Wraps an HTTP handler, adding error logging. If the inner function panics, the outer function recovers, logs, sends an HTTP 500 error response.
func StartHTTPServer ¶
func WriteRPCResponse ¶
func WriteRPCResponse(w http.ResponseWriter, res RPCResponse)
Types ¶
type RPCFunc ¶
type RPCFunc struct {
// contains filtered or unexported fields
}
holds all type information for each function
func NewRPCFunc ¶
wraps a function for quicker introspection
type ResponseWriterWrapper ¶
type ResponseWriterWrapper struct { Status int http.ResponseWriter }
Remember the status for logging
func (*ResponseWriterWrapper) Hijack ¶
func (w *ResponseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error)
implements http.Hijacker
func (*ResponseWriterWrapper) WriteHeader ¶
func (w *ResponseWriterWrapper) WriteHeader(status int)
type WSConnection ¶
type WSConnection struct { QuitService // contains filtered or unexported fields }
a single websocket connection contains listener id, underlying ws connection, and the event switch for subscribing to events
func NewWSConnection ¶
func NewWSConnection(baseConn *websocket.Conn, funcMap map[string]*RPCFunc, evsw *events.EventSwitch) *WSConnection
new websocket connection wrapper
func (*WSConnection) OnStart ¶
func (wsc *WSConnection) OnStart() error
wsc.Start() blocks until the connection closes.
func (*WSConnection) OnStop ¶
func (wsc *WSConnection) OnStop()
type WebsocketManager ¶
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) WebsocketHandler ¶
func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Request)
Upgrade the request/response (via http.Hijack) and starts the WSConnection.