Documentation
¶
Overview ¶
Package handler provides implementations of the jrpc2.Assigner interface, and support for adapting functions to the jrpc2.Handler interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Func ¶
A Func adapts a function having the correct signature to a jrpc2.Handler.
func New ¶
func New(fn interface{}) Func
New adapts a function to a jrpc2.Handler. The concrete value of fn must be a function with one of the following type signatures:
func(context.Context) (Y, error) func(context.Context, X) error func(context.Context, X) (Y, error) func(context.Context, ...X) (Y, error) func(context.Context, *jrpc2.Request) (Y, error) func(context.Context, *jrpc2.Request) (interface{}, error)
for JSON-marshalable types X and Y. New will panic if the type of fn does not have one of these forms. The resulting method will handle encoding and decoding of JSON and report appropriate errors.
Functions adapted by in this way can obtain the *jrpc2.Request value using the jrpc2.InboundRequest helper on the context value supplied by the server.
type Map ¶
A Map is a trivial implementation of the jrpc2.Assigner interface that looks up method names in a map of static jrpc2.Handler values.
func NewService ¶
func NewService(obj interface{}) Map
NewService adapts the methods of a value to a map from method names to Handler implementations as constructed by New. It will panic if obj has no exported methods with a suitable signature.
type ServiceMap ¶
A ServiceMap combines multiple assigners into one, permitting a server to export multiple services under different names.
Example:
m := handler.ServiceMap{ "Foo": jrpc2.NewService(fooService), // methods Foo.A, Foo.B, etc. "Bar": jrpc2.NewService(barService), // methods Bar.A, Bar.B, etc. }
func (ServiceMap) Assign ¶
func (m ServiceMap) Assign(method string) jrpc2.Handler
Assign splits the inbound method name as Service.Method, and passes the Method portion to the corresponding Service assigner. If method does not have the form Service.Method, or if Service is not set in m, the lookup fails and returns nil.
func (ServiceMap) Names ¶
func (m ServiceMap) Names() []string
Names reports the composed names of all the methods in the service, each having the form Service.Method.