Lightning talk by Lukas Rieder
@Elixir UG Berlin, August 9 2018
Slide 2
Slide 2 text
$ whoami
Slide 3
Slide 3 text
Lukas Rieder
Freelance Consultant
Slide 4
Slide 4 text
I work for companies doing
Infrastructure, ETL,
Application development,
HTTP Edge, Kubernetes
Slide 5
Slide 5 text
I work with Elixir
Slide 6
Slide 6 text
Configuration in Elixir
Slide 7
Slide 7 text
Do not: Store dynamic
configuration
use Mix.Config
config :app_name, :config, System.get_env("CONFIG")
Slide 8
Slide 8 text
Do: Point to dynamic configuration using
distillery REPLACE_OS_VARS
use Mix.Config
config :app_name, :config, "${CONFIG}"
Slide 9
Slide 9 text
Do not: Read configuration at
compile time
defmodule Foo do
@config Application.get_env(:foo_app, :config)
end
Slide 10
Slide 10 text
Do: Read configuration at
runtime
defmodule Foo do
def config() do
Application.get_env(:foo_app, :config)
end
end
Slide 11
Slide 11 text
Library configuration in
Elixir
Slide 12
Slide 12 text
Stateless: Nothing to worry
Slide 13
Slide 13 text
Stateful: Provide Callback
Modules
Slide 14
Slide 14 text
Stateful: Provide Callback Modules
# init/1 Callback
module MyPlug do
def init(opts) do
opts
end
end
Slide 15
Slide 15 text
Stateful: Allow User-modules
and define otp_app
Slide 16
Slide 16 text
Stateful: Allow User-modules and
define otp_app
use Mix.Config
config :config_app, ConfigApp.Repo,
adapter: Ecto.Adapters.Postgres,
# …
Slide 17
Slide 17 text
Stateful: Allow User-modules and
define otp_app
defmodule ConfigApp.Repo do
use Ecto.Repo, otp_app: :config_app
end
Slide 18
Slide 18 text
Stateful: Allow User-modules and
define otp_app
defmodule Ecto.Repo do
defmacro __using__(opts) do
quote bind_quoted: [opts: opts] do
@otp_app opts[:otp_app]
# …
end
end
end
Slide 19
Slide 19 text
Stateful: Application libraries
should be standard!
Slide 20
Slide 20 text
Configuration overwrites,
inheritance?
Slide 21
Slide 21 text
use Mix.Config
config :app_name, AppName,
where: "elixir_ug",
who: "lukas"