diff --git a/.gitignore b/.gitignore index cdf6bec..8aabffb 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ pom.xml.asc .hgignore .hg/ .calva/ -.clj-kondo/ +**/.clj-kondo/.cache/ .lsp/ target/ node_modules/ diff --git a/clinic/.clj-kondo/config.edn b/clinic/.clj-kondo/config.edn new file mode 100644 index 0000000..6828faa --- /dev/null +++ b/clinic/.clj-kondo/config.edn @@ -0,0 +1 @@ +{:lint-as {mount.core/defstate clojure.core/def}} diff --git a/clinic/.gitignore b/clinic/.gitignore index fb8e63c..c15939a 100644 --- a/clinic/.gitignore +++ b/clinic/.gitignore @@ -1,4 +1,5 @@ -.clj-kondo/ +.clj-kondo/.cache .lsp/ target/ resources/public/js +.env diff --git a/clinic/project.clj b/clinic/project.clj index 5313a6b..bb5a07c 100644 --- a/clinic/project.clj +++ b/clinic/project.clj @@ -1,7 +1,9 @@ (defproject clinic "0.1.0-SNAPSHOT" :description "Onboarding project #2" :url "https://github.com/nilenso/ashutosh-onboarding/blob/main/clinic" - :dependencies [[org.clojure/clojure "1.11.1"]] + :dependencies [[aero "1.1.6"] + [mount "0.1.17"] + [org.clojure/clojure "1.11.1"]] :source-paths ["src/clj"] :main ^:skip-aot clinic.core :target-path "target/%s" diff --git a/clinic/resources/config.edn b/clinic/resources/config.edn new file mode 100644 index 0000000..8777d4b --- /dev/null +++ b/clinic/resources/config.edn @@ -0,0 +1,2 @@ +{:fhir-server-base-url #or [#env FHIR_SERVER_BASE_URL "http://localhost:8090/fhir"] + :http-port #long #or [#env HTTP_PORT 8080]} diff --git a/clinic/src/clj/clinic/config.clj b/clinic/src/clj/clinic/config.clj new file mode 100644 index 0000000..6fba511 --- /dev/null +++ b/clinic/src/clj/clinic/config.clj @@ -0,0 +1,14 @@ +(ns clinic.config + (:refer-clojure :exclude [read]) + (:require [aero.core :as aero] + [clojure.java.io :as io] + [mount.core :refer [defstate]])) + +(defstate ^:private config + :start (-> "config.edn" + (io/resource) + (aero/read-config)) + :stop nil) + +(defn read [key] + (get config key)) diff --git a/clinic/src/clj/clinic/core.clj b/clinic/src/clj/clinic/core.clj index 7a1094e..ffe7992 100644 --- a/clinic/src/clj/clinic/core.clj +++ b/clinic/src/clj/clinic/core.clj @@ -1,4 +1,7 @@ -(ns clinic.core) +(ns clinic.core + (:require [clinic.config :as config] + [mount.core :as mount])) (defn -main [] - (prn "Hello, world!")) + (mount/start) + (prn (config/read :fhir-server-base-url) (config/read :http-port))) diff --git a/clinic/test/clj/clinic/config_test.clj b/clinic/test/clj/clinic/config_test.clj new file mode 100644 index 0000000..91ad4e7 --- /dev/null +++ b/clinic/test/clj/clinic/config_test.clj @@ -0,0 +1,10 @@ +(ns clj.clinic.config-test + (:require [clojure.test :refer [deftest is]] + [aero.core :as aero] + [clinic.config :as config] + [mount.core :as mount])) + +(deftest read-test + (with-redefs [aero/read-config (constantly {:test-key "test-val"})] + (mount/start #'config/config) + (is (= "test-val" (config/read :test-key)))))