File tree 2 files changed +12
-3
lines changed
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,15 @@ defmodule Geolix.Plug do
3
3
Geolix Plug
4
4
"""
5
5
6
+ import Plug.Conn
7
+
6
8
@ behaviour Plug
7
9
8
10
def init ( opts ) , do: opts
9
11
10
- def call ( conn , _opts ) , do: conn
12
+ def call ( conn , opts ) do
13
+ lookup = Geolix . lookup ( conn . remote_ip , opts )
14
+
15
+ put_private ( conn , :geolix , lookup )
16
+ end
11
17
end
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ defmodule Geolix.PlugTest do
5
5
defmodule Router do
6
6
use Plug.Router
7
7
8
- plug Geolix.Plug
8
+ plug Geolix.Plug , where: :city
9
9
10
10
plug :match
11
11
plug :dispatch
@@ -16,6 +16,9 @@ defmodule Geolix.PlugTest do
16
16
@ opts Router . init ( [ ] )
17
17
18
18
test "returns 200" do
19
- assert 200 == conn ( :get , "/" ) |> Router . call ( @ opts ) |> Map . fetch! ( :status )
19
+ conn = conn ( :get , "/" ) |> Router . call ( @ opts )
20
+
21
+ assert 200 == conn . status
22
+ refute conn . private [ :geolix ]
20
23
end
21
24
end
You can’t perform that action at this time.
0 commit comments