good morning!!!!

Skip to content
Snippets Groups Projects
conn_helpers.go 614 B
Newer Older
a's avatar
a committed
package jsonrpc
a's avatar
a committed

a's avatar
a committed
import "context"
a's avatar
a committed

a's avatar
a committed
// Do
a's avatar
a committed
func Do[T any](ctx context.Context, c Conn, method string, args any) (*T, error) {
a's avatar
a committed
	var t T
a's avatar
a committed
	err := c.Do(ctx, &t, method, args)
a's avatar
a committed
	if err != nil {
a's avatar
a committed
		return nil, err
a's avatar
a committed
	}
a's avatar
a committed
	return &t, nil
}

a's avatar
a committed
// Call
a's avatar
a committed
func Call[T any](ctx context.Context, c Conn, method string, args ...any) (*T, error) {
	var t T
a's avatar
a committed
	err := c.Do(ctx, &t, method, args)
a's avatar
a committed
	if err != nil {
		return nil, err
	}
	return &t, nil
a's avatar
a committed
}
a's avatar
a committed

a's avatar
a committed
// CallInto
a's avatar
a committed
func CallInto(ctx context.Context, c Conn, result any, method string, args ...any) error {
	err := c.Do(ctx, result, method, args)
	if err != nil {
		return err
	}
	return nil
}