Validating whether a responder is configured
Next, we want to validate whether an HTTPServer
module is properly configured to use a responder since it is a requirement to use the HTTPServer
module. We can do this by checking for the presence of a responder configuration at the time of starting the server. So, in the start/1
function, let’s validate the presence of a responder before creating a listening socket:
lib/goldcrest_http_server.ex
defmodule Goldcrest.HTTPServer do # .. def start(port) do ensure_configured!() case :gen_tcp.listen(port, @server_options) do {:ok, sock} -> Logger.info("Started a webserver on port #{port}") listen(sock) {:error, error} -> ...