burrow

package
v0.0.13-a Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2016 License: MIT Imports: 13 Imported by: 3

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

View Source
const (
	RpcVersion        string = "2.0"
	RpcParseError     int    = -32700
	RpcInvalidRequest int    = -32600
	RpcMethodNotFound int    = -32601
	RpcInvalidParams  int    = -32602
	RpcInternalError  int    = -32603
	RpcServerError    int    = -32000
)

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 RenderTemplate(template string, vars ...interface{}) (string, error)

func VarsInterface

func VarsInterface(vars map[string]string) map[string]interface{}

Types

type App

type App struct {
	Prefix         string
	Name           string
	Methods        []Method
	Debug          bool
	Port           string
	Router         *mux.Router
	TLSCertificate *string
	TLSPrivateKey  *string
}

func NewApp

func NewApp(name string) *App

func (*App) GetPort

func (app *App) GetPort() string

func (*App) Run

func (app *App) Run() error

func (*App) RunTLS

func (app *App) RunTLS(cert, key *string) error

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 MethodParams map[string]*Param

type Param

type Param struct {
	Key       string                  `json:"key,omitempty"`
	Value     interface{}             `json:"value,omitempty"`
	Validator func(interface{}) error `json:"-"`
	Help      string                  `json:"help,omitempty"`
}

func (*Param) GetInt

func (p *Param) GetInt() int

func (*Param) GetString

func (p *Param) GetString() string

func (*Param) GetUint

func (p *Param) GetUint() uint

func (*Param) Validate

func (p *Param) Validate() error

type RequestContext

type RequestContext struct {
	Request    *RequestMessage
	Connection *Connection
	HTTPWriter http.ResponseWriter
	HTTPReader *http.Request
	Params     MethodParams
}

func (*RequestContext) Render

func (ctx *RequestContext) Render(template string) (string, error)

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

type RouteHandler struct {
	Prefix string
	Routes []Route
}

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)

func (*RouteHandler) Subrouter

func (h *RouteHandler) Subrouter(r *mux.Router) (subrouter *mux.Router)

Jump to

Keyboard shortcuts

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