Documentation ¶
Overview ¶
Package exporter 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 ¶
- type ServiceExporter
- func NewExporter(ctx context.Context, etcdURL string, ttl int64) (*ServiceExporter, error)
- func NewExporterFromClient(ctx context.Context, kv etcd.KV, lease etcd.Lease, ttl int64) (*ServiceExporter, error)
- func NewExporterFromConfig(ctx context.Context, config etcd.Config, ttl int64) (*ServiceExporter, error)
- func (e *ServiceExporter) ListenAndServeNamedHTTP(ctx context.Context, servicename, addr string, handler http.Handler) error
- func (e *ServiceExporter) NewExportedPort(ctx context.Context, network, ip, service string) (net.Listener, error)
- func (e *ServiceExporter) NewExportedTLSPort(ctx context.Context, network, ip, servicename string, config *tls.Config) (net.Listener, error)
- func (e *ServiceExporter) UnexportPort(ctx context.Context) error
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 ¶
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, kv etcd.KV, lease etcd.Lease, ttl int64) ( *ServiceExporter, error)
NewExporterFromClient creates a new exporter by reading etcd flags from the specified configuration file.
func NewExporterFromConfig ¶
func NewExporterFromConfig(ctx context.Context, config etcd.Config, ttl int64) ( *ServiceExporter, error)
NewExporterFromConfig creates a new exporter by reading etcd flags from the specified configuration. 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 (*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.