internal/jsonrpc2_v2: add Func convenience wrappers for the Binder and Preempter interfaces

Change-Id: Ib21dabb908c13d9bbf50f053a342a8644d3ee68b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388596
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Bryan C. Mills 2022-02-28 11:24:36 -05:00 • committed by Gopher Robot
commit 5d6e2930bf

View file

@ -28,6 +28,15 @@ type Binder interface {
Bind(context.Context, *Connection) (ConnectionOptions, error)
}
// A BinderFunc implements the Binder interface for a standalone Bind function.
type BinderFunc func(context.Context, *Connection) (ConnectionOptions, error)
func (f BinderFunc) Bind(ctx context.Context, c *Connection) (ConnectionOptions, error) {
return f(ctx, c)
}
var _ Binder = BinderFunc(nil)
// ConnectionOptions holds the options for new connections.
type ConnectionOptions struct {
// Framer allows control over the message framing and encoding.