mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-19 05:30:03 +02:00
Add ability to omit params member from request (#62)
The JSON-RPC 2.0 specification allows the params member of a request to be omitted [1]. Before this commit, this library did not allow the params member to be omitted when sending a request. When the params argument of the Conn.Call/Conn.DispatchCall or Conn.Notify method was set to nil, then Request.Params was set to the JSON encoding of nil which is null. This commit adds a CallOption named OmitNilParams. If OmitNilParams is used when sending a request with params set to nil, then the params member in the JSON encoding of Request is omitted. If the OmitNilParams option is not used then the previous behavior is maintained. In other words, the changes in this commit are backwards compatible. References [1]: https://www.jsonrpc.org/specification#request_object
This commit is contained in:
parent
e1f9fdf1bb
commit
8012d49686
3 changed files with 137 additions and 8 deletions
|
|
@ -46,3 +46,12 @@ func StringID() CallOption {
|
|||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// OmitNilParams returns a call option that instructs requests to omit params
|
||||
// values of nil instead of JSON encoding them to null.
|
||||
func OmitNilParams() CallOption {
|
||||
return callOptionFunc(func(r *Request) error {
|
||||
r.OmitNilParams = true
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue