gob

package module
v0.0.0-...-ad00d80 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

README

gob-RPC

GoDoc

Documentation

Overview

Package gob provides a gob codec for Gorilla RPC over HTTP.

Why Gob

At time of writing, the Gorilla project only offers one codec for its RPC over HTTP package, namely JSON. JSON is nice and all, but for Go programs talking to Go programs, gob is superior because it takes advantage of the common type system, not to mention the simple truth that a binary format takes up less space on the wire.

The primary use case for this package is web applications consisting of a Go server on the backend and GopherJS on the frontend. If those two components are in place, then there's no real reason to choose JSON over gob. It's even possible to have both enabled simultaneously, thanks to Gorilla RPC's use of the Content-Type header to specify codec.

Note that net/rpc over Websockets is another way to enable gob-RPC, but due to the way that net/rpc service methods are defined, it's impossible to get any context about the client during an RPC method call unless it's provided explicitly each time. Gorilla RPC signatures add an *http.Request parameter that can be examined to get this type of information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRequest

func BuildRequest(url, method string, args interface{}) (*http.Request, error)

BuildRequest builds an HTTP request for calling a gob-RPC method.

The body of the request is created using EncodeClientRequest(), the verb is set to POST, and the Content-Type header is set to "application/gob; charset=binary".

func DecodeClientResponse

func DecodeClientResponse(r io.Reader, reply interface{}) (err error)

DecodeClientResponse decodes the response body of a client request into the interface reply.

func EncodeClientRequest

func EncodeClientRequest(method string, args interface{}) ([]byte, error)

EncodeClientRequest encodes parameters for a gob-RPC client request.

func NewError

func NewError(text string) error

NewError returns a gob-registered error that formats as the given text.

Unfortunately, errors created by the standard library's errors package are not registered with encoding/gob, which is necessary in order to send it over the wire via gob, and since the struct is private to the package, there's no way for us to do it for them. As a result, returning an error using errors.New(...) from an RPC method, when using this encoding, will cause the client to receive an EOF error

Types

type Codec

type Codec struct {
}

func NewCodec

func NewCodec() *Codec

NewCodec returns a new gob codec to register with a Gorilla RPC server.

func (*Codec) NewRequest

func (c *Codec) NewRequest(r *http.Request) rpc.CodecRequest

type CodecRequest

type CodecRequest struct {
	// contains filtered or unexported fields
}

func (*CodecRequest) Method

func (c *CodecRequest) Method() (string, error)

func (*CodecRequest) ReadRequest

func (c *CodecRequest) ReadRequest(args interface{}) (err error)

func (*CodecRequest) WriteError

func (c *CodecRequest) WriteError(w http.ResponseWriter, _ int, err error)

func (*CodecRequest) WriteResponse

func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{})

Jump to

Keyboard shortcuts

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