1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-18 21:20:02 +02:00

Add a way to specify more non-standard-compliant fields to Request

This change introduces `ExtraField`, a `CallOption` that can add
arbitrary fields to the top-level JSON-RPC Request message.

Fixes: https://github.com/sourcegraph/jsonrpc2/issues/49
This commit is contained in:
lhchavez 2021-07-26 21:46:01 +00:00
parent 5cdc7d6ccd
commit f987817f79
5 changed files with 123 additions and 16 deletions

View file

@ -19,6 +19,15 @@ func Meta(meta interface{}) CallOption {
})
}
// ExtraField returns a call option which attaches the given name/value pair to
// the JSON-RPC 2.0 request. This can be used to add arbitrary extensions to
// JSON RPC 2.0.
func ExtraField(name string, value interface{}) CallOption {
return callOptionFunc(func(r *Request) error {
return r.SetExtraField(name, value)
})
}
// PickID returns a call option which sets the ID on a request. Care must be
// taken to ensure there are no conflicts with any previously picked ID, nor
// with the default sequence ID.