Confo allows simple access to ambient configuration provided through environment variables.
First include Confo where you need it and then fetch your applications configuration with the confo function.
(ns my.project (:require [confo.core :refer [confo]])) (def config (confo :myproject))
The config symbol will now be a hash-map, loaded with any environment variables that match the name myproject. So for instance you could have configuration like this...
export MYPROJECT_USER="foo" export MYPROJECT_BAR="some other value" export MYPROJECT_WITH_BARS="bazzle"
And these will be available from as...
(:user config) ; => "foo" (:bar config) ; => "some other value" (:with-bars config) ; => "bazzle"
You can also specify default values that will be used if any configuration is not specified.
(confo :myproject :port 123 :name "Some Value")
When checking default values, Confo will also try to coerce the types of any environment variables to the matching type of their default. So for instance if you need a port number to start your service on then you'll probably want to configure a default...
(def config (confo :myproject :port 123))
So now, any port specified through the environment variable MYPROJECT_PORT will be coerced to an integer.
This is available for extension via a multimethod confo.core/coerce.
Defaults specified as keywords will be created as such.
(:bubble (confo :foo :bubble :default)) ; => :bobble
Another "coercable" default is a CSV to a vector. So...
(:bar (confo :foo :bar )) ; => ["1" "2" "3"]
(:odb (confo :foo :odb false)) ; => true
Confo is available from Clojars.
Unit testing provided by Midje