Slide 1

Slide 1 text

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"

Slide 22

Slide 22 text

use Mix.Config config :app_name, AppName, where: "elixir_ug", who: "lukas"
 
 config :app_name, AppName.Conf, where: "elixir_conf"

Slide 23

Slide 23 text

GetConf.get_conf(:app_name, AppName, :where)
 # => "elixir_ug"

Slide 24

Slide 24 text

GetConf.get_conf(:app_name, AppName, :where)
 # => "elixir_ug"
 GetConf.get_conf(:app_name, AppName.Foo, :where)
 # => "elixir_conf"

Slide 25

Slide 25 text

GetConf.get_conf(:app_name, AppName, :where)
 # => "elixir_ug"
 GetConf.get_conf(:app_name, AppName.Foo, :where)
 # => "elixir_conf"
 GetConf.get_conf(:app_name, AppName.Foo, :who)
 # => "lukas"

Slide 26

Slide 26 text

defmodule AppName defmodule AppName.M1 defmodule AppName.M1.M2 Configuration lookup GetConf.get_conf/3

Slide 27

Slide 27 text

defmodule TestModule use GetConf, otp_app: :app_name def where(), do: get_conf(:where) end TestModule.where()
 # => "elixir_ug" 
 TestModule.get_conf(:where)
 # => "elixir_ug"

Slide 28

Slide 28 text

{:get_conf, "~> 0.1"} Thanks @ Suitepad GmbH
 @ Hildebrando Rueda

Slide 29

Slide 29 text

Upcoming: Flow Based Programming in Elixir {:get_conf, "~> 0.1"}

Slide 30

Slide 30 text

{:get_conf, "~> 0.1"} Thanks & enjoy.

Slide 31

Slide 31 text

{:get_conf, "~> 0.1"} Thanks & enjoy. Lightning talk by Lukas Rieder @Elixir UG Berlin, August 9 2018 [email protected]