{"id":19288342,"url":"https://github.com/techascent/tech.config","last_synced_at":"2025-04-22T04:33:17.307Z","repository":{"id":52704495,"uuid":"119896115","full_name":"techascent/tech.config","owner":"techascent","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-08T17:37:30.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T17:21:04.067Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techascent.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-01T21:31:22.000Z","updated_at":"2021-12-11T22:07:06.000Z","dependencies_parsed_at":"2022-08-22T07:01:33.370Z","dependency_job_id":null,"html_url":"https://github.com/techascent/tech.config","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techascent","download_url":"https://codeload.github.com/techascent/tech.config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223888371,"owners_count":17220083,"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":[],"created_at":"2024-11-09T22:08:45.771Z","updated_at":"2024-11-09T22:08:45.981Z","avatar_url":"https://github.com/techascent.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tech.config [![Build Status](https://travis-ci.com/tech-ascent/tech.config.svg?token=64MLcsqSTjE7SCpD6LB1\u0026branch=master)](https://travis-ci.com/techascent/tech.config)\n\n[![Clojars Project](https://img.shields.io/clojars/v/techascent/tech.config.svg)](https://clojars.org/techascent/tech.config)\n\n`tech.config` is a Clojure library that abstracts configuration from files and env.\n\nThe library works by reading config files named `*-config.edn` from the resources\ndirectory in the uberjar (or in the local repository if running on a repl).\nThis defines a number of config variables and values. An example is as follows:\n\n### Config File (e.g. `app-config.edn`):\n\n    {\n       :my-setting \"value\"\n    }\n\nEach of the settings can be any type, the final type of the value will be\ndecided by base of the precedence hierarchy defined below.\n\n### Usage:\n\n#### Getting config values\n\n    (require '[think.config :refer [get-config]])\n\n    (get-config :my-setting)\n\n#### Overwriting config values\n\nIn the event that you wish to programatically overwrite a config setting, it is\npossible to use the `with-config` macro as follows:\n\n```\n(require '[think.config :refer [get-config with-config]])\n\n(with-config [:my-setting true]\n (get-config :my-setting))       ; =\u003e true\n```\n\n\n### Precedence Hierarchy\n\n`think.config` allows the user of the library to specify config values in\nseveral different ways. Any `*-config.edn` found within the application or a\ndependency will be merged into the config. The order that this occurs is\nreverse alphabetical with `app-config.edn` and `user-config.edn` moved to the\ntop of the stack respectively.\n\nNext, values set either through the `:env` key within a leiningen profile or\nthrough the environment will take precedence over those specified in\n`*-config.edn` files.\n\nIn summary, this hierarchy results in the following ordering (furthest to the left takes precedence):\n`with-config` ➡ `environment` ➡ `:env` in profile.clj ➡  `user-config.edn` ➡ `app-config.edn` ➡ `libraries (a-z)`\n\n### Types\n\nOne major advantage over other configuration options that `think.config` provides is types. The bottom of the configuration stack defines the type (i.e. when a library specifies a default value, it also specifies the type because the `.edn` files are typed. Any configuration layer that overwrites this value gets coerced to the type specified at the base. As a consequence, things specified through the environment (or the command line) which come in a strings will be converted to the appropriate type and the application can read these types without performing the conversion on its own.\n\n### Sources Map\n\nThe sources map (obtained by calling `(get-config-table-str)`) provides a table like the on shown below. This is convenient to show at start up so that it is possible to see where configuration options are being set and what the types are (e.g. strings are shown in \"quotes\"). If something is set by the environment the source will be listed as `environment` and if it is set with the `(with-config)` macro it will be listed as `with-config`.\n\n```\nKey                    Value            Source\n-------------------------------------------------------\n:app-config-overwrite  1                app-config.edn\n:boolean               true             test-config.edn\n:env-config-overwrite  false            environment\n:number                42               test-config.edn\n:os-arch               \"amd64\"          zzz-config.edn\n:os-name               \"Linux\"          zzz-config.edn\n:os-version            \"4.8.0-26-generic\" zzz-config.edn\n:overwrite             30               test-config.edn\n:string                \"hello world\"    with-config\n:user-config-overwrite 2                user-config.edn\n```\n\n### Why another configuration library?\n\nThe advantage to using the config library is that it privies several facilities\nbeyond a standard config reader.\n* All of the settings are placed into the applications resource directory,\n  which means that it's obvious which knobs a user can turn to configure the\n  application.\n* The config settings are all available to the user through the\n  `get-config-table-str` function. This means that it is clear to see how the\n  application was configured. Note that string values will be quoted when returned\n  from this call, making it obvious what type the final value is.\n* There is a merging operation where all of the `*-config.edn` files are read\n  from the uberjar in reverse-alphabetical order (with `user-config.edn` and\n  `app-config.edn` handled specially as mentioned above).. Which means that\n  libraries can specify config settings and then the application can overwrite\n  those settings to custom tune them with an `app-config.edn` file.\n* A config setting can be overwritten with an environment variable (e.g.\n  `MY_SETTING=123 lein run`) to customize the application at runtime. It is\n  also possible to place a file named `user-config.edn` in the resources\n  directory (and git-ignore it) in order to provide development specific\n  settings that don't need to be set with the environment every time.\n* Types are defined by the base of the precedence hierarchy (see above) which\n  means that they can be set using environment variables and read as actual\n  types within the code without having to perform something like `read-string`\n  on each of them.\n* There is a fairly simple way to map them to\n  [command line parameters](examples/tools-cli/src/tools_cli/core.clj).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechascent%2Ftech.config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechascent%2Ftech.config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechascent%2Ftech.config/lists"}