portdiscovery

package
v0.0.0-...-19f3ddf Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package portdiscovery hosts common code shared by CFT containerized services. It provides APIs to write service port number to a metadata file within the container that allows clients (e.g. cros-tool-runner) to look up the info. More info at go/cft-port-discovery

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteServiceMetadata

func WriteServiceMetadata(name string, serviceAddress string, logger *log.Logger) error

WriteServiceMetadata simplifies writing service metadata for all cft services. The service address should be in the format of ".*:port".

Types

type Api

type Api interface {
	// WriteMetadata writes metadata to a file based on Metadata.
	WriteMetadata(Metadata) error
	// GetPortFromAddress returns the port number of the given the address. The
	// address should be in the format of ".*:port".
	GetPortFromAddress(string) (string, error)
}

Api is the interface of the portdiscovery utility.

type Metadata

type Metadata struct {
	Port    string // Mandatory
	Name    string // Optional
	Version string // Optional
}

Metadata represents the data to be written into the metadata file. The data will be translated into standardized key value pair and written into the file following the format of an env file. All values are in string format and will be wrapped with single quotes during the conversion. The metadata file is kept at a minimum level for port discovery only as more complicated and structured data could/should be surfaced through service end points. Future extensions may consider adding a Config object to control the behavior and a map of free formed key-value pair per container (not recommended unless absolutely necessary).

type PortDiscovery

type PortDiscovery struct {
	Api
	Logger *log.Logger
}

PortDiscovery is an implementation of Api.

func (*PortDiscovery) GetPortFromAddress

func (p *PortDiscovery) GetPortFromAddress(address string) (string, error)

func (*PortDiscovery) WriteMetadata

func (p *PortDiscovery) WriteMetadata(metadata Metadata) error

Jump to

Keyboard shortcuts

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