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 RecoverAndLogHandler(handler http.Handler, logger *logging.Logger) http.Handler
- func RegisterRPCFuncs(mux *http.ServeMux, funcMap map[string]*RPCFunc, logger *logging.Logger)
- func StartHTTPServer(listener net.Listener, handler http.Handler, logger *logging.Logger) (*http.Server, error)
- func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse)
- type RPCFunc
- type ResponseWriterWrapper
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 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 RegisterRPCFuncs ¶
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 ¶
func WriteRPCResponseHTTP ¶
func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse)
Types ¶
type RPCFunc ¶
type RPCFunc struct {
// contains filtered or unexported fields
}
RPCFunc contains the introspected type information for a function
func NewRPCFunc ¶
NewRPCFunc wraps a function for introspection. f is the function, args are comma separated argument names
func NewWSRPCFunc ¶
NewWSRPCFunc wraps a function for introspection and use in the websockets.
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)