good morning!!!!

Skip to content
Snippets Groups Projects
Verified Commit 4a73aa5e authored by a's avatar a
Browse files

fix ctxwconn

parent 13dbd0af
Branches
Tags
1 merge request!15Draft: V2
package codec
// BatchElem is an element in a batch request.
type BatchElem struct {
Method string
Params any
IsNotification bool
// The result is unmarshaled into this field. Result must be set to a
// non-nil pointer value of the desired type, otherwise the response will be
// discarded.
Result any
// Error is set if the server returns an error for this request, or if
// unmarshaling into Result fails. It is not set for I/O errors.
Error error
}
......@@ -7,8 +7,7 @@ type clientContextKey struct{}
// ClientFromContext retrieves the client from the context, if any. This can be used to perform
// 'reverse calls' in a handler method.
func ContextWithConn(ctx context.Context, c Conn) context.Context {
client, _ := ctx.Value(clientContextKey{}).(Conn)
return context.WithValue(ctx, clientContextKey{}, client)
return context.WithValue(ctx, clientContextKey{}, c)
}
// ClientFromContext retrieves the client from the context, if any. This can be used to perform
......
package codec
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestConnContext(t *testing.T) {
ctx := context.Background()
{
_, ok := ConnFromContext(ctx)
require.False(t, ok)
}
d := &DummyClient{}
ctx = ContextWithConn(ctx, d)
{
conn, ok := ConnFromContext(ctx)
require.True(t, ok)
require.Equal(t, conn, d)
}
{
conn, ok := StreamingConnFromContext(ctx)
require.True(t, ok)
require.Equal(t, conn, d)
}
}
package codec
import "context"
type DummyClient struct{}
func (d *DummyClient) Notify(ctx context.Context, method string, params any) error {
panic("not implemented") // TODO: Implement
}
func (d *DummyClient) Do(ctx context.Context, result any, method string, params any) error {
panic("not implemented") // TODO: Implement
}
func (d *DummyClient) BatchCall(ctx context.Context, b ...*BatchElem) error {
panic("not implemented") // TODO: Implement
}
func (d *DummyClient) Close() error {
panic("not implemented") // TODO: Implement
}
func (d *DummyClient) Mount(_ Middleware) {
panic("not implemented") // TODO: Implement
}
......@@ -16,6 +16,22 @@ type ResponseWriter interface {
Notify(method string, v any) error
}
// BatchElem is an element in a batch request.
type BatchElem struct {
Method string
Params any
IsNotification bool
// The result is unmarshaled into this field. Result must be set to a
// non-nil pointer value of the desired type, otherwise the response will be
// discarded.
Result any
// Error is set if the server returns an error for this request, or if
// unmarshaling into Result fails. It is not set for I/O errors.
Error error
}
type Response struct {
Version Version `json:"jsonrpc,omitempty"`
ID *ID `json:"id,omitempty"`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment