exportedservice

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

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

Go to latest
Published: Oct 9, 2017 License: BSD-3-Clause Imports: 7 Imported by: 0

README

golang-etcd-exportedservice

etcd exported HTTP/TCP/whatever service ports

This is a library for setting up an anonymous port and registering it with an etcd directory service.

Documentation

Overview

Package exportedservice provides exported named etcd ports. This binds to an anonymous port, exports the host:port pair through etcd and returns the port to the caller.

There are convenience methods for exporting a TLS port and an HTTP service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ServiceExporter

type ServiceExporter struct {
	// contains filtered or unexported fields
}

ServiceExporter exists because we need to initialize our etcd client beforehand and keep it somewhere.

func NewExporter

func NewExporter(ctx context.Context, etcdURL string, ttl int64) (
	*ServiceExporter, error)

NewExporter creates a new exporter object which can later be used to create exported ports and services. This will create a client connection to etcd. If the connection is severed, once the etcd lease is going to expire the port will stop being exported. The specified ttl (which must be at least 5 (seconds)) determines how frequently the lease will be renewed.

func NewExporterFromClient

func NewExporterFromClient(
	ctx context.Context, client *etcd.Client, ttl int64) (
	*ServiceExporter, error)

NewExporterFromClient creates a new exporter by reading etcd flags from the specified configuration file.

func NewFromDefault

func NewFromDefault(ctx context.Context, ttl int64) (*ServiceExporter, error)

NewFromDefault creates a new exporter object which can later be used to create exported ports and services. This will create a client connection to etcd using the flags based DNS autoconfiguration.

If the connection is severed, once the etcd lease is going to expire the port will stop being exported.

The specified ttl (which must be at least 5 (seconds)) determines how frequently the lease will be renewed.

func (*ServiceExporter) ListenAndServeNamedHTTP

func (e *ServiceExporter) ListenAndServeNamedHTTP(
	ctx context.Context, servicename, addr string, handler http.Handler) error

ListenAndServeNamedHTTP makes the default HTTP server listen on "addr" and exports the given "handler". Registers as "servicename".

func (*ServiceExporter) NewExportedPort

func (e *ServiceExporter) NewExportedPort(
	ctx context.Context, network, ip, service string) (net.Listener, error)

NewExportedPort opens a new anonymous port on "ip" and export it through etcd as "servicename". If "ip" is not a host:port pair, the port will be chosen at random.

func (*ServiceExporter) NewExportedTLSPort

func (e *ServiceExporter) NewExportedTLSPort(
	ctx context.Context, network, ip, servicename string,
	config *tls.Config) (net.Listener, error)

NewExportedTLSPort opens a new anonymous port on "ip" and export it through etcd as "servicename" (see NewExportedPort). Associates the TLS configuration "config". If "ip" is a host:port pair, the port will be overridden.

func (*ServiceExporter) UnexportPort

func (e *ServiceExporter) UnexportPort(ctx context.Context) error

UnexportPort removes the associated exported port. This will only delete the most recently exported port. Exported ports will disappear by themselves once the process dies, but this will expedite the process.

Jump to

Keyboard shortcuts

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