webrpc

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2013 License: BSD-3-Clause Imports: 10 Imported by: 65

Documentation

Overview

Package webrpc implements a web-based JSON, Gob and ProtoBuf RPC protocol roughly compatible with google-protorpc. It works in tandem with the go-rpcgen protoc-gen-go plugin, which generates the bindings.

By default, webrpc.DefaultServeMux is handled by the default HTTP package, so it will interoperate with standard HTTP servers and AppEngine.

Index

Constants

View Source
const (
	// DefaultRPCPath is the prefix of all RPC handlers registered by webrpc
	DefaultRPCPath = "/_webRPC_"
)

Variables

View Source
var DefaultServeMux = ServeMux{}

DefaultServeMux is the default ServeMux used when nil is passed to the Register...Web functions and ListenAndServe.

Functions

func ListenAndServe

func ListenAndServe(addr string, mux ServeMux) error

ListenAndServe is a utility function for starting up the HTTP server without needing to import the net/http package.

func Post

func Post(protocol Protocol, base *url.URL, method string, in, out interface{}) error

Post is used by the code generated automatically by protoc-gen-go for making RPC calls remotely.

func RegisterProtocol

func RegisterProtocol(p Protocol)

Types

type Call

type Call struct {
	http.ResponseWriter
	*http.Request

	ContentType string
}

A Call is an incoming request. These are used in the code generated automatically by protoc-gen-go.

func (*Call) ReadRequest

func (c *Call) ReadRequest(pb interface{}) error

ReadRequest is used by the code generated automatically by protoc-gen-go.

func (*Call) WriteResponse

func (c *Call) WriteResponse(pb interface{}) error

WriteResponse is used by the code generated automatically by protoc-gen-go.

type Handler

type Handler func(*Call) error

A Handler processes an incoming RPC request. These are generated automatically by protoc-gen-go for service definitions and don't usually need to be registered manually.

type Protocol

type Protocol interface {
	String() string // Return the MIME type of the protocol
	Decode(io.Reader, interface{}) error
	Encode(io.Writer, interface{}) error
}

A Protocol is a predefined encoder/decoder for WebRPC.

var Gob Protocol = gobProtocol{}

Gob implements the Go Object implementation of the webrpc.Protocol interface.

var JSON Protocol = jsonProtocol{}

JSON implements the Javascript Object Notation implementation of the webrpc.Protocol interface.

var ProtoBuf Protocol = pbProtocol{}

ProtoBuf implements the Google Protocol Buffer implementation of the webrpc.Protocol interface. This is currently not allowed on AppEngine.

type ServeMux

type ServeMux map[string]Handler

A ServeMux collects all of the handlers registered (usually by the Register...Web functions generated by protoc-gen-go) for handling by net/http.

func (ServeMux) Handle

func (m ServeMux) Handle(path string, handler Handler) error

Handle adds a new handler for an RPC. This is used by the code generated automatically by protoc-gen-go.

func (ServeMux) ServeHTTP

func (m ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP creates a Call and calls the appropriate RPC handler for the given path.

Jump to

Keyboard shortcuts

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