json

package
v1.27.2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2018 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package json provides the JSON encoding for YARPC.

To make outbound requests using this encoding,

client := json.New(clientConfig)
var resBody GetValueResponse
err := client.Call(ctx, "getValue", &GetValueRequest{...}, &resBody)

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

f(ctx context.Context, body $reqBody) ($resBody, error)

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

Use the Procedure function to build procedures to register against a Router.

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

Similarly, to register a oneway JSON procedure, define functions in the format,

f(ctx context.Context, body $reqBody) error

Where $reqBody is a map[string]interface{} or pointer to a struct.

Use the OnewayProcedure function to build procedures to register against a Router.

dispatcher.Register(json.OnewayProcedure("setValue", SetValue))
dispatcher.Register(json.OnewayProcedure("runTask", RunTask))

Index

Constants

View Source
const Encoding transport.Encoding = "json"

Encoding is the name of this encoding.

Variables

This section is empty.

Functions

func OnewayProcedure added in v0.4.0

func OnewayProcedure(name string, handler interface{}) []transport.Procedure

OnewayProcedure builds a Procedure from the given JSON handler. handler must be a function with a signature similar to,

f(ctx context.Context, body $reqBody) error

Where $reqBody is a map[string]interface{} or pointer to a struct.

func Procedure

func Procedure(name string, handler interface{}) []transport.Procedure

Procedure builds a Procedure from the given JSON handler. handler must be a function with a signature similar to,

f(ctx context.Context, body $reqBody) ($resBody, error)

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

func Register deprecated

func Register(r transport.RouteTable, rs []transport.Procedure)

Register calls the RouteTable's Register method.

This function exists for backwards compatibility only. It will be removed in a future version.

Deprecated: Use the RouteTable's Register method directly.

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, procedure string, reqBody interface{}, resBodyOut interface{}, opts ...yarpc.CallOption) error
	CallOneway(ctx context.Context, procedure string, reqBody interface{}, opts ...yarpc.CallOption) (transport.Ack, error)
}

Client makes JSON requests to a single service.

func New

New builds a new JSON client.

Jump to

Keyboard shortcuts

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