Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for parameter injection. #82

Merged
merged 1 commit into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/creachadair/jrpc2"
"github.com/creachadair/jrpc2/handler"
"github.com/creachadair/jrpc2/jctx"
"github.com/creachadair/jrpc2/server"
"github.com/fortytw2/leaktest"
)
Expand All @@ -23,37 +22,17 @@ func BenchmarkRoundTrip(b *testing.B) {
return nil, nil
}),
}
ctxClient := &jrpc2.ClientOptions{EncodeContext: jctx.Encode}
tests := []struct {
desc string
cli *jrpc2.ClientOptions
srv *jrpc2.ServerOptions
}{
{"C01-CTX-B", nil, &jrpc2.ServerOptions{DisableBuiltin: true, Concurrency: 1}},
{"C01-CTX+B", nil, &jrpc2.ServerOptions{Concurrency: 1}},
{"C04-CTX-B", nil, &jrpc2.ServerOptions{DisableBuiltin: true, Concurrency: 4}},
{"C04-CTX+B", nil, &jrpc2.ServerOptions{Concurrency: 4}},
{"C12-CTX-B", nil, &jrpc2.ServerOptions{DisableBuiltin: true, Concurrency: 12}},
{"C12-CTX+B", nil, &jrpc2.ServerOptions{Concurrency: 12}},

{"C01+CTX-B", ctxClient,
&jrpc2.ServerOptions{DecodeContext: jctx.Decode, DisableBuiltin: true, Concurrency: 1},
},
{"C01+CTX+B", ctxClient,
&jrpc2.ServerOptions{DecodeContext: jctx.Decode, Concurrency: 1},
},
{"C04+CTX-B", ctxClient,
&jrpc2.ServerOptions{DecodeContext: jctx.Decode, DisableBuiltin: true, Concurrency: 4},
},
{"C04+CTX+B", ctxClient,
&jrpc2.ServerOptions{DecodeContext: jctx.Decode, Concurrency: 4},
},
{"C12+CTX-B", ctxClient,
&jrpc2.ServerOptions{DecodeContext: jctx.Decode, DisableBuiltin: true, Concurrency: 4},
},
{"C12+CTX+B", ctxClient,
&jrpc2.ServerOptions{DecodeContext: jctx.Decode, Concurrency: 12},
},
{"C01-B", nil, &jrpc2.ServerOptions{DisableBuiltin: true, Concurrency: 1}},
{"C01+B", nil, &jrpc2.ServerOptions{Concurrency: 1}},
{"C04-B", nil, &jrpc2.ServerOptions{DisableBuiltin: true, Concurrency: 4}},
{"C04+B", nil, &jrpc2.ServerOptions{Concurrency: 4}},
{"C12-B", nil, &jrpc2.ServerOptions{DisableBuiltin: true, Concurrency: 12}},
{"C12+B", nil, &jrpc2.ServerOptions{Concurrency: 12}},
}
for _, test := range tests {
b.Run(test.desc, func(b *testing.B) {
Expand Down
10 changes: 2 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Client struct {
done *sync.WaitGroup // done when the reader is finished at shutdown time

log func(string, ...interface{}) // write debug logs here
enctx encoder
snote func(*jmessage)
scall func(context.Context, *jmessage) []byte
chook func(*Client, *Response)
Expand All @@ -41,7 +40,6 @@ func NewClient(ch channel.Channel, opts *ClientOptions) *Client {
c := &Client{
done: new(sync.WaitGroup),
log: opts.logFunc(),
enctx: opts.encodeContext(),
snote: opts.handleNotification(),
scall: opts.handleCallback(),
chook: opts.handleCancel(),
Expand Down Expand Up @@ -421,7 +419,7 @@ func (c *Client) stop(err error) {
// value of params must be either nil or encodable as a JSON object or array.
func (c *Client) marshalParams(ctx context.Context, method string, params interface{}) (json.RawMessage, error) {
if params == nil {
return c.enctx(ctx, method, nil) // no parameters, that is OK
return nil, nil // no parameters, that is OK
}
pbits, err := json.Marshal(params)
if err != nil {
Expand All @@ -432,11 +430,7 @@ func (c *Client) marshalParams(ctx context.Context, method string, params interf
// an array or an object.
return nil, &Error{Code: code.InvalidRequest, Message: "invalid parameters: array or object required"}
}
bits, err := c.enctx(ctx, method, pbits)
if err != nil {
return nil, err
}
return bits, err
return pbits, nil
}

func newPending(ctx context.Context, id string) (context.Context, *Response) {
Expand Down
121 changes: 0 additions & 121 deletions jctx/example_test.go

This file was deleted.

149 changes: 0 additions & 149 deletions jctx/jctx.go

This file was deleted.

Loading