View Source Wayfarer.Utils (wayfarer v0.6.1)

A grab-bag of useful functions which are used all over the codebase.

Summary

Functions

Verify an IP address and convert it into a tuple.

Verify a port number.

Verify a scheme.

Convert a target tuple into a tuple safe for injection into a match spec.

Convert a list of targets into a match spec guard.

Convert a scheme, address, port tuple into a URI.

Types

@type address_input() :: IP.Address.t() | String.t() | :inet.ip_address()
@type port_number() :: 1..65535
@type scheme() :: :http | :https | :ws | :wss
@type transport() :: :http1 | :http2 | :auto

Functions

Link to this function

sanitise_ip_address(address)

View Source
@spec sanitise_ip_address(address_input()) ::
  {:ok, :inet.ip_address()} | {:error, any()}

Verify an IP address and convert it into a tuple.

@spec sanitise_port(port_number()) :: {:ok, port_number()} | {:error, any()}

Verify a port number.

@spec sanitise_scheme(scheme()) :: {:ok, scheme()} | {:error, any()}

Verify a scheme.

@spec target_to_ms({scheme(), :inet.ip_address(), port_number(), transport()}) ::
  {{scheme(), {:inet.ip_address()}, port_number(), transport()}}

Convert a target tuple into a tuple safe for injection into a match spec.

Link to this function

targets_to_ms_guard(var, list)

View Source
@spec targets_to_ms_guard(atom(), [
  {scheme(), :inet.ip_address(), port_number(), transport()}
]) :: [
  {atom(), any(), any()}
]

Convert a list of targets into a match spec guard.

Link to this function

to_uri(scheme, address, port)

View Source
@spec to_uri(scheme(), address_input(), port_number()) ::
  {:ok, URI.t()} | {:error, any()}

Convert a scheme, address, port tuple into a URI.