简体   繁体   English

Phoenix-访问Erlang依赖性

[英]Phoenix - Access Erlang dependency

I'm using Phoenix (v1.2.1) to build a REST API , but I know very little about Elixir and pretty much zero about Erlang . 我正在使用Phoenix (v1.2.1)构建REST API ,但是我对Elixir知之甚少,而对Erlang则知之甚少。

As part of the create action on one of my controllers, group_controller.ex , I need to query an external source to generate some data. 作为对我的一个控制器group_controller.excreate动作的一部分,我需要查询一个外部源以生成一些数据。 The logic for producing this query is in an Erlang dependency that has been added to my mix.exs deps and successfully installed in the deps directory... so that is all good. 产生此查询的逻辑是在Erlang依赖关系中,该依赖关系已添加到我的mix.exs deps中,并成功安装在deps目录中……所以一切都很好。

However, I haven't the slightest idea how to import the module or access its functionality in my controller (or anywhere in my app, for that matter). 但是,我丝毫不知道如何导入模块或在控制器中(或在应用程序中的任何位置)访问模块的功能。 Can I even use an Erlang dependency out of the box in a Phoenix app, or does it need to be transpiled to Elixir? 我是否可以在Phoenix应用程序中立即使用Erlang依赖项,还是需要将其转换为Elixir?

If I were writing this in ES6, I would write something like 如果我是用ES6编写的,我会写类似

import {FunctionA, FunctionB} from 'module'

easy as pie... how can I accomplish that in Phoenix when the dependency is written in Erlang? 简单易如反掌...当用Erlang编写依赖项时,如何在Phoenix中实现呢?

Thank you! 谢谢!

Calling Methods on Erlang Modules Erlang模块上的调用方法

Erlang modules are accessible as atoms of their module names in elixir, and you can call their methods like any other Modules: 在elixir中,Erlang模块可以作为其模块名称的atoms来访问,并且您可以像调用其他模块一样调用它们的方法:

:module.function(arguments)

For Example: 例如:

To call the uniform/0 method of the Erlang random module, you can do this: 要调用Erlang random模块的uniform/0方法,您可以执行以下操作:

:random.uniform

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM