1
我探索藥劑的世界,並建立以下內容:檢查URL參數是一個數字
defmodule Hello do
def init(default_opts) do
IO.puts "starting up App..."
default_opts
end
def call(conn, _opts) do
route(conn.method, conn.path_info, conn)
end
def route("GET", ["customers", cust_id], conn) do
# check parameter
IO.puts user_id
IO.puts "Check if user_id is a number:"
IO.puts is_number(cust_id)
if is_number(cust_id) do
conn |> Plug.Conn.send_resp(200, "Customer id: #{cust_id}")
else
conn |> Plug.Conn.send_resp(404, "Couldn't find customer, sorry!")
end
end
我很奇怪,爲什麼is_number
功能(或is_integer
)是提供虛假的結果。我使用的網址是:http://localhost:4000/customers/12