stevensonmt

stevensonmt

I’m starting to work on my first real app and can’t quite understand the runtime configuration story. I would like to use a TOML file to hold the configuration data. My plan is to look for this config.toml file in the path $XDG_CONFIG_HOME/my_app/config.toml or perhaps even iterate through $XDG_CONFIG_DIRS appending /myapp/config.toml to each until one is found. If no file is found a default config will be included.

I would like to use the Toml library to parse the config but I’m not following the guidance on organizing the configuration from the docs. I’m also not clear on how one would access the config data later.

From here I gather I need a config/runtime.exs to fetch the configuration data. I assume this is where the code suggested in the Toml docs goes:

# config/runtime.exs

config_providers: [
  {Toml.Provider, [
    path: {:system, "XDG_CONFIG_DIR", "myapp.toml",
    transforms: [...]
  ]}
]

So let’s say I have something like this snippet of the example from the Toml docs:

# This is an example of something that would be ignored
title = "My config file"

# We're expecting something like this:
[myapp]
key = "value"

How do I later access myapp.key to use “value”?

I’m wondering if it’s Applicationg.get_env/3?

Showing Posts 1 to 8

cmo

cmo

You can also use something like Vapor.

jswanner

jswanner

@stevensonmt, I believe you’ll want to look into Config.Provider. It’s your mix.exs file you’ll be adding that configuration to.

stevensonmt

stevensonmt OP

Thanks that makes sense. But then what goes into the config/runtime.exs file? And am I correct that Application.get_env and the like are how to retrieve the configuration data?

@cmo thanks! Vapor looks very straightforward.

cmo

cmo

If you’re using the Toml config provider because you don’t want to use runtime.exs, then don’t use runtime.exs. They’re two different sources of config. One does not load the other. You could use both if you want to confuse yourself or if you want the runtime.exs stuff ever so slightly further out of reach than the config.toml.

And yes, config is retrieved with Application.get_env and friends.

stevensonmt

stevensonmt OP

Excellent. Thanks for your help. I’m trying not to assume end users would be familiar with Elixir but would be with TOML.

stevensonmt

stevensonmt OP

Just a hint for anyone stumbling on this thread later, Vapor.load!(config_providers) does not put the configuration keys into the application env. I’m guessing it just parses and stores in memory? IDK, but after loading the providers you have to call Application.put_env(:your_application, :key, value) for each configuration setting of interest. If I’m doing this wrong I hope someone can correct me, but without that step my application env is just an empty keyword list.

jswanner

jswanner

It wasn’t explicitly stated but I assumed before you were using GitHub - bitwalker/toml-elixir: An implementation of TOML for Elixir projects, compliant with the latest specification · GitHub.

If using Vapor, then yes you’ll need to call Application.put_env/4 yourself, if you’re planning to access those values via the application environment.

stevensonmt

stevensonmt OP

Vapor is using toml-elixir as a dependency. Before Vapor was mentioned on this thread I had intended to use it directly, but with Vapor I can allow multiple user-specified config formats.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews