gpt4 book ai didi

elixir - 在 config.exs 中使用 Application.app_dir( :my_app, "priv")

转载 作者:行者123 更新时间:2023-12-03 16:14:54 27 4
gpt4 key购买 nike

我正在尝试将库配置设置为指向 priv 中的文件路径(geoip db) :'

config :geolix, databases: [
%{
id: :city,
adapter: Geolix.Adapter.MMDB2,
source: Application.app_dir(:zipbooks, "priv") |> Path.join("data/GeoLite2-City.mmdb")
}
]

但我的
config :zipbooks, …

位于顶部的同一个文件中。我收到此错误:
** (Mix.Config.LoadError) could not load config config/config.exs
** (ArgumentError) unknown application: :zipbooks

我使用发行版,所以我不能硬编码 priv path 因为它的相对位置会改变。我用过 Application.app_dir(:zipbooks, "priv")过去可靠,所以我想知道如何在 config.exs 中完成此操作

最佳答案

我猜这是不可能的。所以我最终做的是这样的:

def start(_type, _args) do
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: ZB.Supervisor]

Application.get_env(:zipbooks, :env)
|> children
|> Supervisor.start_link(opts)
|> after_start
end

defp after_start({:ok, _} = result) do
Geolix.load_database(%{
id: :city,
adapter: Geolix.Adapter.MMDB2,
source: Application.app_dir(:zipbooks, "priv") |> Path.join("data/GeoLite2-City.mmdb")
})
result
end
defp after_start(result), do: result

关于elixir - 在 config.exs 中使用 Application.app_dir( :my_app, "priv"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46854998/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com