Cherrypicker.Routes (cherrypicker v0.1.0)

Copy Markdown View Source

The route table: name → loopback port, held in ETS behind a GenServer so writes serialize and reads stay lock-free on the hot proxy path.

Names are the DNS label before .localhost: lowercase letters, digits, and hyphens, dots allowed for subdomain-style names (api.myapp). cherrypicker itself is reserved for the control API.

Summary

Functions

Returns a specification to start this module under a supervisor.

Removes a route; removing an absent route is not an error.

The port for a name, if routed.

Every route, name-sorted.

Registers or replaces a route. Errors on bad names and ports.

Types

name()

@type name() :: String.t()

route()

@type route() :: %{name: name(), port: :inet.port_number()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

delete(name)

@spec delete(name()) :: :ok

Removes a route; removing an absent route is not an error.

fetch(name)

@spec fetch(name()) :: {:ok, :inet.port_number()} | :error

The port for a name, if routed.

list()

@spec list() :: [route()]

Every route, name-sorted.

put(name, port)

@spec put(name(), :inet.port_number()) :: :ok | {:error, String.t()}

Registers or replaces a route. Errors on bad names and ports.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()