Wayfarer.Utils (wayfarer v0.6.2)

View Source

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

address_input()

@type address_input() :: IP.Address.t() | String.t() | :inet.ip_address()

port_number()

@type port_number() :: 1..65535

scheme()

@type scheme() :: :http | :https | :ws | :wss

transport()

@type transport() :: :http1 | :http2 | :auto

Functions

sanitise_ip_address(address)

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

Verify an IP address and convert it into a tuple.

sanitise_port(port)

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

Verify a port number.

sanitise_scheme(scheme)

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

Verify a scheme.

target_to_ms(arg)

@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.

targets_to_ms_guard(var, list)

@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.

to_uri(scheme, address, port)

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

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