Documentation ¶
Overview ¶
Package burrow is a small framework for building web apps that accept HTTP, JSON-RPC and WebSocket requests and use the same business logic.
Index ¶
- Constants
- func LoadRequestMessage(data []byte) (msg *RequestMessage, err *CodedError)
- func ReadRequestMessage(content io.Reader) (msg *RequestMessage, err *CodedError)
- func RenderTemplate(template string, vars ...interface{}) (string, error)
- func VarsInterface(vars map[string]string) map[string]interface{}
- type App
- type CodedError
- type Connection
- type HTTPHandler
- type Method
- type MethodHandler
- type MethodParams
- type Param
- type RequestContext
- type RequestMessage
- type ResponseMessage
- type Route
- type RouteHandler
- func (h *RouteHandler) MountHelp(methods map[string]Method)
- func (h *RouteHandler) MountIo(ms map[string]Method)
- func (h *RouteHandler) MountMethods(methods []Method)
- func (r *RouteHandler) MountRoutes(methods []Method)
- func (h *RouteHandler) MountRpc(ms map[string]Method)
- func (h *RouteHandler) Subrouter(r *mux.Router) (subrouter *mux.Router)
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func LoadRequestMessage ¶
func LoadRequestMessage(data []byte) (msg *RequestMessage, err *CodedError)
func ReadRequestMessage ¶
func ReadRequestMessage(content io.Reader) (msg *RequestMessage, err *CodedError)
func RenderTemplate ¶
func VarsInterface ¶
Types ¶
type App ¶
type CodedError ¶
type CodedError struct { Code int `json:"code"` Data interface{} `json:"data,omitempty"` Message string `json:"message"` }
func Cerrorf ¶
func Cerrorf(code int, msg string, vals ...interface{}) (err *CodedError)
func (*CodedError) Error ¶
func (err *CodedError) Error() string
func (*CodedError) ResponseMessage ¶
func (err *CodedError) ResponseMessage() (msg *ResponseMessage)
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
connection is an middleman between the websocket connection and the hub.
func NewConnection ¶
func NewConnection(ws *websocket.Conn) *Connection
func (*Connection) Close ¶
func (c *Connection) Close()
func (*Connection) Respond ¶
func (c *Connection) Respond(msg *ResponseMessage)
func (*Connection) Write ¶
func (c *Connection) Write(content interface{})
type HTTPHandler ¶
type HTTPHandler func(w http.ResponseWriter, r *http.Request) (msg *ResponseMessage)
func (HTTPHandler) ServeHTTP ¶
func (handle HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Method ¶
type Method struct { Name string `json:"name"` Handler MethodHandler `json:"-"` Params MethodParams `json:"params,omitempty"` Route string `json:"route,omitempty"` Help string `json:"help,omitempty"` }
func (Method) Execute ¶
func (m Method) Execute(ctx *RequestContext) (msg *ResponseMessage)
func (Method) WrapParams ¶
func (m Method) WrapParams(params map[string]interface{}) (MethodParams, error)
type MethodHandler ¶
type MethodHandler func(ctx *RequestContext) (interface{}, *CodedError)
type MethodParams ¶
type Param ¶
type RequestContext ¶
type RequestContext struct { Request *RequestMessage Connection *Connection HTTPWriter http.ResponseWriter HTTPReader *http.Request Params MethodParams }
type RequestMessage ¶
type RequestMessage struct { Id *string `json:"id"` JsonRpc string `json:"jsonrpc"` Method *string `json:"method"` Params map[string]interface{} `json:"params"` }
func (*RequestMessage) MethodName ¶
func (req *RequestMessage) MethodName() string
func (*RequestMessage) String ¶
func (req *RequestMessage) String() string
func (*RequestMessage) Validate ¶
func (req *RequestMessage) Validate() (err *CodedError)
type ResponseMessage ¶
type ResponseMessage struct { Error *CodedError `json:"error,omitempty"` Id *string `json:"id,omitempty"` JsonRpc string `json:"jsonrpc,omitempty"` Result interface{} `json:"result,omitempty"` }
func RespondMsg ¶
func RespondMsg(id string, content interface{}) (msg *ResponseMessage)
TODO make a request.Respond(msg interface{}) that populates id for you
func SuccessMsg ¶
func SuccessMsg(content interface{}) (msg *ResponseMessage)
func (*ResponseMessage) Marshal ¶
func (msg *ResponseMessage) Marshal() ([]byte, error)
type Route ¶
type Route struct { Pattern string Handler HTTPHandler }
type RouteHandler ¶
func (*RouteHandler) MountHelp ¶
func (h *RouteHandler) MountHelp(methods map[string]Method)
func (*RouteHandler) MountIo ¶
func (h *RouteHandler) MountIo(ms map[string]Method)
func (*RouteHandler) MountMethods ¶
func (h *RouteHandler) MountMethods(methods []Method)
func (*RouteHandler) MountRoutes ¶
func (r *RouteHandler) MountRoutes(methods []Method)
func (*RouteHandler) MountRpc ¶
func (h *RouteHandler) MountRpc(ms map[string]Method)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.