Skip to content

Instantly share code, notes, and snippets.

@supernullset
Created October 21, 2016 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supernullset/b97010b065ef382f4ed68fe8c68bc6dc to your computer and use it in GitHub Desktop.
Save supernullset/b97010b065ef382f4ed68fe8c68bc6dc to your computer and use it in GitHub Desktop.
defmodule ErrorCodes.Repo do
use Ecto.Repo, otp_app: :error_codes
end
defmodule ErrorCodes.ErrorCode do
use Ecto.Schema
schema "errors" do
end
end
defmodule ErrorCodes.Router do
import Plug.Conn
import Ecto.Query
alias ErrorCodes.Repo, as: R
alias ErrorCodes.ErrorCode, as: EC
def init(opts), do: opts
def call(%Plug.Conn{request_path: "/error-codes"} = conn, opts) do
res = R.all(from ec in EC, select: ec.id)
send_resp(conn, 200, inspect(res))
end
end
defmodule ErrorCodes do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# Define workers and child supervisors to be supervised
supervisor(ErrorCodes.Repo, []),
Plug.Adapters.Cowboy.child_spec(:http, ErrorCodes.Router, [], [port: 4001])
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: ErrorCodes.Supervisor]
Supervisor.start_link(children, opts)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment