Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Elixir + Plug version #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions elixir/on_plug/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/_build
/deps
erl_crash.dump
*.ez
8 changes: 8 additions & 0 deletions elixir/on_plug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Elixir + Plug
======

```
$ mix do deps.get, compile
$ MIX_ENV=prod iex -S mix
$ wrk -c 64 -d 30s http://localhost:4000/10
```
24 changes: 24 additions & 0 deletions elixir/on_plug/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for third-
# party users, it should be done in your mix.exs file.

# Sample configuration:
#
# config :logger, :console,
# level: :info,
# format: "$date $time [$level] $metadata$message\n",
# metadata: [:user_id]

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
12 changes: 12 additions & 0 deletions elixir/on_plug/lib/app_router.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule AppRouter do
use Plug.Router

plug :match
plug :dispatch


get "/:n" do
n = String.to_integer(n)
conn |> send_resp 200, to_string(Fibonacci.get(n))
end
end
14 changes: 14 additions & 0 deletions elixir/on_plug/lib/fibonacci.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Fibonacci do
def get(0) do
0
end

def get(1) do
1
end

def get(n) when n > 0 do
get(n-1) + get(n-2)
end

end
7 changes: 7 additions & 0 deletions elixir/on_plug/lib/on_plug.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule OnPlug do
use Application

def start(_type, _args) do
{:ok, _} = Plug.Adapters.Cowboy.http AppRouter, []
end
end
38 changes: 38 additions & 0 deletions elixir/on_plug/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule OnPlug.Mixfile do
use Mix.Project

def project do
[app: :on_plug,
version: "0.0.1",
elixir: "~> 1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
end

# Configuration for the OTP application
#
# Type `mix help compile.app` for more information
def application do
[
mod: {OnPlug, []},
applications: [:cowboy, :plug]
]
end

# Dependencies can be Hex packages:
#
# {:mydep, "~> 0.3.0"}
#
# Or git/path repositories:
#
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
#
# Type `mix help deps` for more examples and options
defp deps do
[
{:cowboy, "~> 1.0.0"},
{:plug, "~> 0.12"}
]
end
end
4 changes: 4 additions & 0 deletions elixir/on_plug/mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%{"cowboy": {:hex, :cowboy, "1.0.0"},
"cowlib": {:hex, :cowlib, "1.0.1"},
"plug": {:hex, :plug, "0.13.0"},
"ranch": {:hex, :ranch, "1.0.0"}}
7 changes: 7 additions & 0 deletions elixir/on_plug/test/on_plug_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule OnPlugTest do
use ExUnit.Case

test "the truth" do
assert 1 + 1 == 2
end
end
1 change: 1 addition & 0 deletions elixir/on_plug/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()