Skip to content

Commit

Permalink
clinic: add config module
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshgngwr committed Oct 5, 2023
1 parent 7137ddf commit 088af3d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pom.xml.asc
.hgignore
.hg/
.calva/
.clj-kondo/
**/.clj-kondo/.cache/
.lsp/
target/
node_modules/
Expand Down
1 change: 1 addition & 0 deletions clinic/.clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:lint-as {mount.core/defstate clojure.core/def}}
3 changes: 2 additions & 1 deletion clinic/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.clj-kondo/
.clj-kondo/.cache
.lsp/
target/
resources/public/js
.env
4 changes: 3 additions & 1 deletion clinic/project.clj
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions clinic/resources/config.edn
Original file line number Diff line number Diff line change
@@ -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]}
14 changes: 14 additions & 0 deletions clinic/src/clj/clinic/config.clj
Original file line number Diff line number Diff line change
@@ -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))
7 changes: 5 additions & 2 deletions clinic/src/clj/clinic/core.clj
Original file line number Diff line number Diff line change
@@ -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)))
10 changes: 10 additions & 0 deletions clinic/test/clj/clinic/config_test.clj
Original file line number Diff line number Diff line change
@@ -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)))))

0 comments on commit 088af3d

Please sign in to comment.