Skip to content

🔀 Dynamic is my second name!

Compare
Choose a tag to compare
@Strech Strech released this 06 Jul 20:15
· 41 commits to master since this release

In this release, all the private client configuration options become dynamic and may be resolved at runtime or at compile-time. It's defined by the presence of the otp_app option.

If you set the otp_app configuration the value lookup will follow this logic

OTP env value → Client value → Default value

Let's take a look at this example with private client MyClient and :my_app OTP application

# config/config.exs
config :my_app, MyClient, registry_url: "http://my-app.io"

# lib/my_client.ex
defmodule MyClient do
  use Avrora.Client,
    otp_app: :my_app,
    registry_url: "http://never-used.com",
    names_cache_ttl: 42
end

As the result, configuration values will look like this

MyClient.Config.registry_url() == "http://my-app.io" # (comes from runtime environment)
MyClient.Config.names_cache_ttl() == 42 # (comes from compile-time options)
MyClient.Config.registry_schemas_autoreg() == true # (comes from compile-time option defaults)

🚤 Bonus

Most of the generated Avrora.Client code for Config module gets rid of strings interpolation on runtime and moves it to the compile-rime and some hot paths were moved to compile-time.

Thanks a lot for this release to @juanperi 💙