{"id":22980359,"url":"https://github.com/jlangch/kt-config","last_synced_at":"2025-04-02T09:23:06.269Z","repository":{"id":109653042,"uuid":"99270480","full_name":"jlangch/kt-config","owner":"jlangch","description":"Utility for reading configurations. Configuration settings can be defined using dot and/or scoped notation.","archived":false,"fork":false,"pushed_at":"2017-08-29T08:55:33.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T00:28:40.553Z","etag":null,"topics":["kotlin"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlangch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-03T20:04:20.000Z","updated_at":"2017-08-03T20:40:33.000Z","dependencies_parsed_at":"2023-04-12T06:48:45.586Z","dependency_job_id":null,"html_url":"https://github.com/jlangch/kt-config","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlangch%2Fkt-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlangch%2Fkt-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlangch%2Fkt-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlangch%2Fkt-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlangch","download_url":"https://codeload.github.com/jlangch/kt-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246785868,"owners_count":20833594,"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":["kotlin"],"created_at":"2024-12-15T01:38:56.516Z","updated_at":"2025-04-02T09:23:06.249Z","avatar_url":"https://github.com/jlangch.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"kt-config\n=========\n\nUtility for reading configuration files. Configuration settings can be defined using dot and/or scoped notation.\n\n\n## Overview\n\n - implemented in plain Kotlin with no dependencies\n - can load from string, files, URLs, or classpath\n - supports dot notation for names and nested sections\n - override properties with Java system properties and environment variables\n - global substitutions\n \n \n## Example\n\n```\ndef host = \"foo.org\"\n\n# Common section\ncommon {\n  user = \"john.doe\"\n}\n\n# Database section\ndb {\n  h2 {\n    driver = \"org.h2.Driver\"\n    url = \"jdbc:h2:tcp://${host}:9567/~data/db;MVCC=TRUE\"\n  }\n  \n  postgresql {\n    driver=\"org.postgresql.Driver\"\n    url = \"jdbc:postgresql://${host}:5432/serviceplanet\"\n  }\n}\n```\n\n##### Dot notation\n\n```\n# Common section\ncommon.user = \"john.doe\"\n\n# Test section\ntest.host = \"foo.org\"\ntest.port = \"8000\"\n```\n\n##### Mixed notation\n\n```\n# Common section\ncommon.user = \"john.doe\"\n\n# Test section\ntest {\n  host = \"foo.org\"\n  port = \"8000\"\n\n  # Database section\n  db {\n    # H2\n    h2 {\n      driver = \"org.h2.Driver\"\n      url = \"jdbc:h2:tcp://localhost:9567/~data/db;MVCC=TRUE\"\n    }\n  \n    #PostgreSQL\n    postgresql {\n      driver=\"org.postgresql.Driver\"\n      url = \"jdbc:postgresql://localhost:5432/serviceplanet\"\n    }\n  }\n}\n```\n\n\n##### Using Definitions\n\n```\n# Definitions favor DRY. Definitions can be refereneced as\n# ${name}.\n# All environment variables are available as implicit definitions\n# prefixed with 'env.' e.g. 'env.HOME'. \n# Java system properties are available as implicit definitions\n# prefixed with 'system.' e.g 'system.io.temp' \n\n# define the port\ndef port = \"8000\"\ndef database = \"abc.db\"\n\n\napp {\n  dir {\n    home = \"${env.HOME}\"         # uses Environment variable 'HOME'\n    temp = \"${system.io.temp}\"   # uses Java system property 'io.temp'\n  }\n}\n\ndb {\n  h2 {\n    driver = \"org.h2.Driver\"\n    url = \"jdbc:h2:tcp://localhost:${port}/~data/${database}\"\n  }\n  postgresql {\n    driver=\"org.postgresql.Driver\"\n    url = \"jdbc:postgresql://localhost:${port}/${database}\"\n  }\n}\n```\n\n\n## Usage\n\nThe `ConfigReader` can be created with a configuration `String` or by\npassing an `InputStream`. It returns always configuration values in\na flat _dot_ notation (e.g. _db.h2.port = 8000_). The parsed `Config` \nobject can be converted to a `Map\u003cString,String\u003e` or a `Properties` \nobject optionally.\n\n#### Examples\n```kotlin\nval config: Config = ConfigReader(\"....\").read()\n```\n\n```kotlin\nval config: Map\u003cString,String\u003e = ConfigReader(\"....\").read().toMap()\n```\n\n```kotlin\nval config: Properties = ConfigReader(\"....\").read().toProperties()\n```\n\nThe configuration:\n```\ndef port = \"8000\"\ndef database = \"sample.db\"\n\ndb {\n  postgresql {\n    driver=\"org.postgresql.Driver\"\n    url = \"jdbc:postgresql://localhost:${port}/${database}\"\n  }\n}\n```\n\nReturns two configuration values:\n\n- db.postgresql.driver -\u003e org.postgresql.Driver\n- db.postgresql.url -\u003e jdbc:postgresql://localhost:8000/sample.db\n\n\n\n#### Selecting sub configurations\n\n```\n# Common section\ncommon.user = \"john.doe\"\n\n# Test section\ntest {\n  host = \"foo.org\"\n  port = \"8000\"\n}\n\n# UAT section\nuat {\n  host = \"foo.org\"\n  port = \"8001\"\n}\n```\n\n\n```kotlin\nval config: Config = ConfigReader(\"....\").read().getSubConfig(\"common\", \"test\")\n```\n\nReturns three configuration values:\n\n- user -\u003e john.doe\n- host -\u003e foo.org\n- port -\u003e 8001\n\n\n#### Passing user definitions\n\nThe _definitions_ in the config file may be overridden \nprogrammatically:\n\n```\ndef port = \"8000\"\ndef database = \"abc.db\"\n\ndb {\n  postgresql {\n    driver=\"org.postgresql.Driver\"\n    url = \"jdbc:postgresql://localhost:${port}/${database}\"\n  }\n}\n```\n\n```kotlin\nval config: Config = ConfigReader(\"....\", hashMapOf(\"port\" to \"8080\")).read()\n```\n\n## Error handling\n\nThe `ConfigReader` throws a `ConfigurationException` whenever \nthe configuration is not conform to the specification or a definition\nreference can not be resolved. The exception provides the caller \nwith an error message and a position (row, col) of the error. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlangch%2Fkt-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlangch%2Fkt-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlangch%2Fkt-config/lists"}