json

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package json provides the JSON encoding for YARPC.

To make outbound requests using this encoding,

client := json.New(channel)
var resBody GetValueResponse
resMeta, err := client.Call(
	yarpc.NewReqMeta(ctx).Procedure("getValue"),
	&GetValueRequest{...},
	&resBody,
)

To register a JSON procedure, define functions in the format,

f(meta yarpc.ReqMeta, body $reqBody) ($resBody, yarpc.ResMeta, error)

Where '$reqBody' and '$resBody' are either pointers to structs representing your request and response objects, or map[string]interface{}.

Use the Register and Procedure functions to register the procedures with a Registry.

json.Register(r, json.Procedure("getValue", GetValue))
json.Register(r, json.Procedure("setValue", SetValue))

Index

Constants

View Source
const Encoding transport.Encoding = "json"

Encoding is the name of this encoding.

Variables

This section is empty.

Functions

func Register

func Register(reg transport.Registry, registrant Registrant)

Register registers the procedures defined by the given JSON registrant with the given registry.

Handlers must have a signature similar to the following or the system will panic.

f(ctx context.Context, reqMeta yarpc.ReqMeta, body $reqBody) ($resBody, yarpc.ResMeta, error)

Where $reqBody and $resBody are a map[string]interface{} or pointers to structs.

Types

type Client

type Client interface {
	// Call performs an outbound JSON request.
	//
	// resBodyOut is a pointer to a value that can be filled with
	// json.Unmarshal.
	//
	// Returns the response or an error if the request failed.
	Call(ctx context.Context, reqMeta yarpc.CallReqMeta, reqBody interface{}, resBodyOut interface{}) (yarpc.CallResMeta, error)
}

Client makes JSON requests to a single service.

func New

func New(c transport.Channel) Client

New builds a new JSON client.

type Registrant

type Registrant interface {
	// contains filtered or unexported methods
}

Registrant is used for types that define or know about different JSON procedures.

func Procedure

func Procedure(name string, handler interface{}) Registrant

Procedure builds a Registrant with a single procedure in it. handler must be a function with a signature similar to,

f(ctx context.Context, reqMeta yarpc.ReqMeta, body $reqBody) ($resBody, yarpc.ResMeta, error)

Where $reqBody and $resBody are a map[string]interface{} or pointers to structs.

Jump to

Keyboard shortcuts

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