protorpc

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: BSD-3-Clause, BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package gorilla/rpc/protorpc provides a codec for ProtoRPC over HTTP services.

To register the codec in a RPC server:

import (
	"http"
	"github.com/gorilla/rpc/v2"
	"github.com/gorilla/rpc/v2/protorpc"
)

func init() {
	s := rpc.NewServer()
	s.RegisterCodec(protorpc.NewCodec(), "application/json")
	// [...]
	http.Handle("/rpc", s)
}

A codec is tied to a content type. In the example above, the server will use the ProtoRPC codec for requests with "application/json" as the value for the "Content-Type" header.

This package implement ProtoRPC, based on the JSON-RPC transport, it differs in that it uses HTTP as its envelope.

Example: POST /Service.Method Request:

{
  "requestField1": "value1",
  "requestField2": "value2",
}

Response:

{
  "responseField1": "value1",
  "responseField2": "value2",
}

Check the gorilla/rpc documentation for more details:

http://gorilla-web.appspot.com/pkg/rpc

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec struct {
}

Codec creates a CodecRequest to process each request.

func NewCodec

func NewCodec() *Codec

NewCodec returns a new ProtoRPC Codec.

func (*Codec) NewRequest

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

NewRequest returns a CodecRequest.

type CodecRequest

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

CodecRequest decodes and encodes a single request.

func (*CodecRequest) Method

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

Method returns the RPC method for the current request.

The method uses a dotted notation as in "Service.Method".

func (*CodecRequest) ReadRequest

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

ReadRequest fills the request object for the RPC method.

func (*CodecRequest) WriteError

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

func (*CodecRequest) WriteResponse

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

WriteResponse encodes the response and writes it to the ResponseWriter.

Jump to

Keyboard shortcuts

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