Writing an HTTP server package
Let’s create a new goldcrest folder for all Goldcrest-related code, examples, and packages. Inside goldcrest, we can create our web server package by running the following command:
$ mix new goldcrest_http_server
Let’s now define the Goldcrest.HTTPServer module, which will be our main web server module:
lib/goldcrest_http_server.ex
defmodule Goldcrest.HTTPServer do
@moduledoc """
Starts a HTTP server on the given port
This server also logs all requests
"""
require Logger
@server_options [
active: false,
packet: :http_bin,
reuseaddr: true
]
def start(port) do
case :gen_tcp.listen(port, @server_options) do
{:ok, sock} ->
Logger...