good morning!!!!

Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
dialer.go 556 B
package codecs

import (
	"context"
	"errors"
	"fmt"
	"net/url"

	"gfx.cafe/open/jrpc/pkg/jsonrpc"
)

var ErrSchemeNotSupported = errors.New("url scheme not supported")

func DialContext(ctx context.Context, u string) (jsonrpc.Conn, error) {
	pu, err := url.Parse(u)
	if err != nil {
		return nil, err
	}
	dialer := dialers[pu.Scheme]
	if dialer == nil {
		return nil, fmt.Errorf("%w: %s", ErrSchemeNotSupported, pu.Scheme)
	}
	return dialer(ctx, u)
}

func Dial(u string) (jsonrpc.Conn, error) {
	ctx := context.Background()
	return DialContext(ctx, u)
}