Skip to content

Commit

Permalink
feat: Add elin.config
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Feb 2, 2024
1 parent 96a636e commit 1ea0034
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/elin/config.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns elin.config
(:require
[aero.core :as aero]
[elin.schema.config :as e.s.config]
[elin.util.file :as e.u.file]
[malli.core :as m]
[malli.transform :as mt]
[medley.core :as medley]))

(def ^:private config-file-name
".elin.edn")

(def ^:private config-transformer
(mt/transformer
mt/default-value-transformer))

(defn load-config
([dir]
(load-config dir {}))
([dir base]
(let [config (some-> (e.u.file/find-file-in-parent-directories dir config-file-name)
(aero/read-config))
config (medley/deep-merge base
(or config {}))]
(m/coerce e.s.config/?Config
config
config-transformer))))
18 changes: 18 additions & 0 deletions src/elin/schema/config.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns elin.schema.config)

(def ^:private ?LogLevel
[:enum :debug :info :warning :error])

(def ^:private ?Log
[:map
[:level {:default :info} ?LogLevel]])

(def ^:private ?Server
[:map
[:host string?]
[:port int?]])

(def ?Config
[:map
[:log {:default {}} ?Log]
[:server ?Server]])

0 comments on commit 1ea0034

Please sign in to comment.