{"id":15647747,"url":"https://github.com/sunng87/stavka","last_synced_at":"2025-04-19T13:50:21.720Z","repository":{"id":32603632,"uuid":"135447892","full_name":"sunng87/stavka","owner":"sunng87","description":"Stavka manages configuration from various sources, for your Clojure application.","archived":false,"fork":false,"pushed_at":"2022-04-06T14:28:42.000Z","size":131,"stargazers_count":44,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T08:23:44.032Z","etag":null,"topics":["clojure","configuration-management"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunng87.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-30T13:37:02.000Z","updated_at":"2024-08-02T18:59:06.000Z","dependencies_parsed_at":"2022-08-07T17:45:58.425Z","dependency_job_id":null,"html_url":"https://github.com/sunng87/stavka","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fstavka","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fstavka/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fstavka/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fstavka/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunng87","download_url":"https://codeload.github.com/sunng87/stavka/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249707509,"owners_count":21313858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","configuration-management"],"created_at":"2024-10-03T12:20:51.081Z","updated_at":"2025-04-19T13:50:21.702Z","avatar_url":"https://github.com/sunng87.png","language":"Clojure","funding_links":["https://liberapay.com/Sunng/donate"],"categories":[],"sub_categories":[],"readme":"# stavka\n\n[![Build Status](https://travis-ci.org/sunng87/stavka.png?branch=master)](https://travis-ci.org/sunng87/stavka)\n[![Clojars](https://img.shields.io/clojars/v/stavka.svg)](https://clojars.org/stavka)\n[![Cljdoc](https://img.shields.io/badge/cljdoc-stavka-blue.svg)](https://cljdoc.xyz/d/stavka/stavka)\n[![License](https://img.shields.io/badge/license-eclipse-blue.svg)](https://github.com/sunng87/stavka/blob/master/LICENSE)\n[![Donate](https://img.shields.io/badge/donate-liberapay-yellow.svg)](https://liberapay.com/Sunng/donate)\n\nStavka (Ставка) is the high command of your clojure application,\nwhich manages configuration from various sources.\n\n## Features\n\n* Extensible configuration sources and formats\n  * Sources:\n    * Classpath `(classpath)`\n    * File system `(file)`\n    * URL `(url)`, enabled when `clj-http` on classpath\n    * JDBC (see [examples](https://github.com/sunng87/stavka/blob/master/examples/stavka/example/jdbc.clj))\n    * Kubernetes configmap (see [examples](https://github.com/sunng87/stavka/blob/master/examples/stavka/example/kubernetes.clj))\n  * Formats:\n    * Environment variables `(env)`\n    * JVM options (-D) `(options)`\n    * Commandline options with tools.cli parser `(cli args\n      cli-parser)`, enabled when `clojure.tools.cli` on classpath\n    * EDN `(edn)`\n    * JSON `(json)`, enabled when `cheshire` on classpath\n    * YAML `(yaml)`, enabled when `clj-yaml` on classpath\n    * Properties `(property)`\n* Reloading by\n  * Watching file system `(watch)`, enabled when `hawk` on classpath\n  * Watching file system `(watch2)` using\n    [beholder](https://github.com/nextjournal/beholder) as backend,\n    enabled when `heholder` on classpath\n  * Polling the source `(poll)`\n* Listeners for value changing `(on-change!)`\n* Type conversion `($l) ($f) ($b) ($s)`\n\n\n## Usage\n\n### Setup\n\nUse stavka with [component](https://github.com/stuartsierra/component)\nor [mount](https://github.com/tolitius/mount). You can have multiple\nconfig instance and manage life-cycle of updater.\n\n```clj\n(require '[stavka.core :as sta :refer :all])\n\n;; Use stavka with mount\n(defstate config\n    :start\n    ;; load configuration from multiple sources and merge them like\n    ;; clojure.core/merge.\n    (sta/using\n        ;; using environment variables by default\n        (env)\n        ;; also load edn from classpath\n        (edn (classpath \"/default.edn\"))\n        ;; load another properties from filesystem, and watch is for change\n        (properties (watch (file \"/etc/stavka.properties\")))\n        ;; and fetch a remote json configuration. check every 10 seconds\n        ;; for update.\n        (json (poll (url \"http://somehost/configuration/my.json\") 10000)))\n\n    :stop (stop-updaters! config))\n\n;; Use stavka with component\n(defrecord StavkaConfiguration [config]\n    component/Lifecycle\n    (start [component]\n        (assoc component :config\n            (sta/using\n                (env)\n                (edn (classpath \"/default.edn\"))\n                (properties (watch (file \"/etc/stavka.properties\")))\n                (json (poll (url \"http://somehost/configuration/my.json\") 10000)))))\n    (stop [component]\n        (stop-updaters! config)\n        (assoc component :config nil)))\n```\n\n### Configuration format:\n\n#### ENV\n\n```sh\nexport SOME_CONFIG_KEY=\"some-value\"\n```\n\n#### EDN\n\n```clojure\n{:some {:config {:key \"some-value\"}}}\n```\n\n#### JSON\n\n```javascript\n{\n  \"some\": {\n    \"config\": {\n      \"key\" : \"some-value\"\n    }\n  }\n}\n\n```\n\n#### Properties\n\n```properties\nsome.config.key=some-value\n```\n\n#### Yaml\n\n```yaml\nsome:\n  config:\n    key: some-value\n```\n\n### Get configuration item:\n\n```clj\n;; get configuration\n($ config :some.config.key)\n\n;; get configuration with type convertion\n;; $l: as long\n;; $f: as double\n;; $s: as string\n;; $b: as boolean\n($l config :some.config.key)\n```\n\n### Global config\n\nAnd you can still use stavka globally:\n\n```clj\n(sta/global!\n    (env)\n    (edn (classpath \"/default.edn\"))\n    (properties (watch (file \"/etc/stavka.properties\")))\n    (json (poll (url \"http://somehost/configuration/my.json\") 10000)))\n\n;; use double-$ to access global config\n($$ :some.config.key)\n($$l :some.config.key)\n```\n\n### Listeners\n\nAdd change listener on some key when you have updater configured:\n\n```clj\n(on-change! config :some.config.key\n    (fn [new-value previous-value]\n        ))\n```\n\n## License\n\nCopyright © 2018 Ning Sun\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n\n## Donation\n\nI'm now accepting donation on [liberapay](https://liberapay.com/Sunng/donate),\nif you find my work helpful and want to keep it going.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunng87%2Fstavka","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunng87%2Fstavka","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunng87%2Fstavka/lists"}