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(ctx context.Context, reqMeta 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 Procedure function to build registrants to register against a Registry.
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, reqMeta yarpc.ReqMeta, body $reqBody) error
Where $reqBody is a map[string]interface{} or pointer to a struct.
Use the OnewayProcedure function to build registrants to register against a Registry.
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
func OnewayProcedure(name string, handler interface{}) []transport.Registrant
OnewayProcedure builds a Registrant from the given JSON handler. handler must be a function with a signature similar to,
f(ctx context.Context, reqMeta yarpc.ReqMeta, body $reqBody) error
Where $reqBody is a map[string]interface{} or pointer to a struct.
func Procedure ¶
func Procedure(name string, handler interface{}) []transport.Registrant
Procedure builds a Registrant from the given JSON handler. 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.
func Register
deprecated
func Register(r transport.Registrar, rs []transport.Registrant)
Register calls the Registrar's Register method.
This function exists for backwards compatibility only. It will be removed in a future version.
Deprecated: Use the Registrar'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, reqMeta yarpc.CallReqMeta, reqBody interface{}, resBodyOut interface{}) (yarpc.CallResMeta, error) CallOneway(ctx context.Context, reqMeta yarpc.CallReqMeta, reqBody interface{}) (transport.Ack, error) }
Client makes JSON requests to a single service.