Skip to content

Commit

Permalink
Merge pull request #2 from wuriyanto48/feature/check/fn
Browse files Browse the repository at this point in the history
check valid command using HOF
  • Loading branch information
wuriyanto48 authored Sep 27, 2018
2 parents b944953 + b51fc5c commit 1331728
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/pocket/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Pocket.Server do
defp handle_input(packet, db) when packet |> byte_size != 0 and packet |> is_binary do
IO.inspect byte_size(packet), label: "Packet "
command = packet |> String.split |> Enum.at(0) |> String.upcase
if command === "SET" || command === "GET" || command === "DEL" do
if is_valid_command?(command) do
key = packet |> String.split |> Enum.at(1)
case command do
"SET" ->
Expand Down Expand Up @@ -72,4 +72,10 @@ defmodule Pocket.Server do
defp handle_input(_, _) do
{:error, "invalid command", "\n"}
end

defp is_valid_command?(command) do
commands = ["SET", "GET", "DEL"]
check = fn(c) -> c == command end
Enum.any?(commands, check)
end
end

0 comments on commit 1331728

Please sign in to comment.