stevensonmt

stevensonmt

Using TOML for user-specified runtime config

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?

Marked As Solved

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.

Also Liked

cmo

cmo

You can also use something like Vapor.

stevensonmt

stevensonmt

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

Last Post!

stevensonmt

stevensonmt

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.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement