joplin icon indicating copy to clipboard operation
joplin copied to clipboard

load-config with alternate "environment" maps?

Open gonewest818 opened this issue 7 years ago • 0 comments

I'd like to propose a modification to "load-config" that optionally allows the caller to supply a function to look up the environment variables. Doing so would support use cases where the developer has adopted adzerk-oss/env or weavejester/environ or whatever is their favorite "12 factor app" style environment configuration lib.

So essentially, something like this

(defn load-config
  ([r] (load-config r System/getenv))
  ([r lookup]
   (edn/read {:readers {'env (fn [x] (lookup (str x)))
                        'envf (fn [[fmt & args]]
                                (apply format fmt
                                       (map #(lookup (str %)) args)))}}
             (PushbackReader. (io/reader r)))))

allowing the user to optionally supply the lookup as a lambda like so

(load-config r #(get (adzerk.env/env) %))

I haven't thought through the joplin.alias use case... Ideally the same "lookup" substitution would work there too.

gonewest818 avatar Nov 06 '17 23:11 gonewest818