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 ¶
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
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 ¶
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.