dogweather
Idea for compiler-checked Application env
Would it be possible for Mix.Config’s config to be a macro which creates accessor functions for the environment variables? E.g.:
# config/config.exs
config :my_app, :key, "value"
…currently enables this kind of access:
"value" = Application.fetch_env!(:my_app, :key)
But instead, I imagine the config macro generates functions at compile time enabling this usage:
"value" = Application.MyApp.key()
The big win is the compile-time checking & LS completion support for MyApp and key. It’s also shorter and more expressive. It doesn’t rely on the programmer remembering to use fetch_env! vs. get_env.
I’m new to macros as well as the Application + Mix.Config system. Would this be possible?
Update: A couple of existing solutions are,
First Post!
LostKobrakai
Config files are scripts (.exs) and therefore don‘t persist their compiled contents. Also the app env is not just filled by those config files. Say you switch to e.g. a runtime secrets provider started with your app. Suddenly all you modules would be missing.
Most Liked
r8code
LostKobrakai
Last Post!
dogweather
Thanks! That provides exactly what I was thinking of, e.g.:
Myapp.Config.hostname/0 # for retrieving the hostname.
Popular in Discussions
Other popular topics
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









