mccraigmccraig.clonfig

https://github.com/mccraigmccraig/clonfig.git

git clone 'https://github.com/mccraigmccraig/clonfig.git'

(ql:quickload :mccraigmccraig.clonfig)
4

clonfig

Build Status

simple environment variable based configuration for clojure apps.

config attributes are defined in a map, along with defaults and post-processor functions (to parse or otherise make-ready config values for consumption by the program).

Usage

add the dependency to your project.clj

[clonfig "0.2.0"]

define any environment variables you want before running a clojure process

ENVIRONMENT=production SMTP_PORT=465 lein repl

the read-config function produces a simple map of config attributes

(use 'clonfig.core)

(def config-defaults {:environment "development"
                      :port [8080 :int]
                      :database-url ["postgresql://localhost/"
                                     (fn [config val] (str val @(:environment config)))]
                      :smtp { :host "localhost"
                              :port [25 :int]}})

(def config (read-config config-defaults))

(:environment config)  ;; "production"
(:port config)         ;; 8080
(:database-url config) ;; "postgresql://localhost/production"
(get-in config [:smtp :host]) ;; "localhost"
(get-in config [:smtp :port]) ;; 465

License

Copyright (C) 2013 mccraigmccraig

Distributed under the Eclipse Public License, the same as Clojure.