Created
October 21, 2016 02:14
-
-
Save supernullset/b97010b065ef382f4ed68fe8c68bc6dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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