Key lookup on steroids in Clojure.
Simplify code by consolidating application configuration concerns!
Config access code is tightly coupled to config. Why let this tight coupling spread all over the code base? Collect config concerns in one place, without repeating yourself, so that the rest of the code remains cleaner.
java.util.Properties
instances.edn
and .properties
files
${foo|bar|baz}
- foo
is looked up, followed by bar
, then baz
Clojars coordinates: [keypin "0.8.3-beta1"]
Requires Java 7 or higher, Clojure 1.7 or higher.
(require '[keypin.core :refer [defkey letval] :as k])
(require '[keypin.util :as u])
;; key with constraints
(defkey
ip [:ip]
port [:port #(< 1023 % 65535) "Port number" {:parser u/str->int}])
;; lookup
(ip {:ip "0.0.0.0" :port "5000"}) ; returns "0.0.0.0"
(port {:ip "0.0.0.0" :port "5000"}) ; returns 5000
(port {:ip "0.0.0.0"}) ; throws IllegalArgumentException
;; key with default value
(defkey
ip [:ip]
port-optional [:port #(< 1023 % 65535) "Port number" {:parser u/str->int :default 3000}])
;; lookup
(port-optional {:ip "0.0.0.0" :port "5000"}) ; returns 5000
(port-optional {:ip "0.0.0.0"}) ; returns 3000
;; lookup form
(letval [{:defs [ip port-optional] :as m} {:ip "0.0.0.0"}]
[ip port-optional m]) ; returns ["0.0.0.0" 3000 {:ip "0.0.0.0"}]
Copyright © 2015-2021 Shantanu Kumar
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation? These fine people already did:
Shantanu Kumar & Vignesh Sarma KEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close