urlconnection

package module
v0.0.0-...-a2c9700 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2021 License: BSD-2-Clause Imports: 12 Imported by: 20

Documentation

Overview

Functions for abstracting target resolution for establishing new network connections by using URLs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(tourl string) (net.Conn, error)

Connect establishes a new connection to the URL, determining the correct handler to use for the schema. For example, tcp://[::1]:8080 will establish a TCP connection to port 8080 on localhost, as will tcp://[::1]/8080.

func ConnectContext

func ConnectContext(ctx context.Context, tourl string) (net.Conn, error)

ConnectContext establishes a new connection to the URL, passing the context down to the handler and determining the correct handler to use for the schema. For example, tcp://[::1]:8080 will establish a TCP connection to port 8080 on localhost, as will tcp://[::1]/8080.

func ConnectTimeout

func ConnectTimeout(tourl string, timeout time.Duration) (net.Conn, error)

ConnectTimeout establishes a new connection to the URL, waiting at most the specified timeout for the connection to be established, determining the correct handler to use for the schema. For example, tcp://[::1]:8080 will establish a TCP connection to port 8080 on localhost, as will tcp://[::1]/8080.

func RegisterConnectionHandler

func RegisterConnectionHandler(name string, handler ConnectionHandler)

RegisterConnectionHandler is used by connection APIs to register their handlers. The URL schema "name" (the part before the dot, i.e. name://...) will be associated with the "handler", which creates connections.

func SetupEtcd

func SetupEtcd(servers []string, cert, key, ca string) error

SetupEtcd instantiates an etcd connection handler with a new etcd client configured from the parameters passed.

cert, key and ca are optional; if empty strings are passed, an unencrypted connection will be used.

func UseExistingEtcd

func UseExistingEtcd(client *clientv3.Client)

UseExistingEtcd instantiates an etcd connection handler pointing at a preconfigured etcd client.

Types

type ConnectionHandler

type ConnectionHandler interface {
	Connect(ctx context.Context, dest *url.URL) (net.Conn, error)
	ConnectTimeout(ctx context.Context, dest *url.URL, timeout time.Duration) (net.Conn, error)
}

ConnectionHandler specifies the basic functionality which must be provided by any connection setup handlers in order to be registered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL