Загрузка проекта Erlang в приложение Elixir

Я создаю приложение Elixir, использующее проект hackney Erlang, и я не могу использовать методы, предоставляемые hackney. Мой mix.exs выглядит так:

defmodule Connecter.Mixfile do
  use Mix.Project

  def project do
    [app: :connecter,
     version: "0.0.1",
     elixir: "~> 1.2-dev",
     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
    [applications: [:logger]]
  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
    [{:hackney, "~>1.4.6"}]
  end
end

И когда я пытаюсь получить доступ к методам библиотеки, я получаю UndefinedFunctionError :

$ iex lib/connecter.ex 
Erlang/OTP 18 [erts-7.1] [source-2882b0c] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Interactive Elixir (1.2.0-dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :h
heart                  hipe_unified_loader    
iex(1)> :h
heart                  hipe_unified_loader    
iex(1)> :hackney
:hackney
iex(2)> method = :get
:get
iex(3)> URL = 'https://friendpaste.com'
** (MatchError) no match of right hand side value: 'https://friendpaste.com'

iex(3)> url = 'https://friendpaste.com'
'https://friendpaste.com'
iex(4)> headers = []
[]
iex(5)> payload = <<>>
""
iex(6)> options = []
[]
iex(7)> {:ok, status, resp, client} = :hackney.request(method, url, headers, payload, options)
** (UndefinedFunctionError) undefined function :hackney.request/5 (module :hackney is not available)
    :hackney.request(:get, 'https://friendpaste.com', [], "", [])

Почему это происходит?


person user3790827    schedule 01.12.2015    source источник


Ответы (1)


Вам понадобится :hackney в качестве обязательного модуля для вашего приложения:

def application do
  [applications: [:logger, :hackney]]
end

См. раздел Приложения — Принципы разработки OTP в документации Erlang OTP.

Кроме того, запуск IEx с iex -S mix гарантирует, что все пути загрузки установлены правильно для ваших микс-зависимостей.

person potatosalad    schedule 01.12.2015
comment
iex -S mix Да, это была самая важная часть. - person user3790827; 02.12.2015