{"id":16019452,"url":"https://github.com/jcomellas/app_config","last_synced_at":"2025-03-18T03:31:19.878Z","repository":{"id":54501040,"uuid":"86883738","full_name":"jcomellas/app_config","owner":"jcomellas","description":"Elixir configuration module that simplifies access to environment variables","archived":false,"fork":false,"pushed_at":"2019-05-03T13:18:33.000Z","size":24,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T06:32:11.447Z","etag":null,"topics":["configuration","elixir","release"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcomellas.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}},"created_at":"2017-04-01T04:28:06.000Z","updated_at":"2023-05-14T14:42:36.000Z","dependencies_parsed_at":"2022-08-13T17:51:00.476Z","dependency_job_id":null,"html_url":"https://github.com/jcomellas/app_config","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcomellas%2Fapp_config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcomellas%2Fapp_config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcomellas%2Fapp_config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcomellas%2Fapp_config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcomellas","download_url":"https://codeload.github.com/jcomellas/app_config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243896758,"owners_count":20365429,"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":["configuration","elixir","release"],"created_at":"2024-10-08T17:04:24.790Z","updated_at":"2025-03-18T03:31:19.624Z","avatar_url":"https://github.com/jcomellas.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AppConfig\n\nHelper configuration module for Elixir that simplifies access to OS environment\nvariables.\n\n\n## Overview\n\nThe [AppConfig](lib/app_config.ex) module contains a macro that adds the\nfollowing functions to the module where it is called:\n\n```elixir\ndef fetch_env(key) :: {:ok, value} | :error\ndef fetch_env!(key) :: value | no_return\ndef get_env(key, value | nil) :: value\ndef get_env_boolean(key, boolean | nil) :: boolean | nil\ndef get_env_integer(key, integer | nil) :: integer | nil\ndef get_env_float(key, float | nil) :: float | nil\n```\n\nThese functions fetch values from an application's environment or from\noperating system (OS) environment variables. The values will be retrieved\nfrom OS environment variables when the following expression is assigned to a\nconfiguration parameter on the application's configuration:\n\n```elixir\n{:system, \"VAR\"}\n```\n\nAn optional default value can be returned when the environment variable is\nnot set to a specific value by using the following format:\n\n```elixir\n{:system, \"VAR\", \"default\"}\n```\n\nThe [AppConfig](lib/app_config.ex) module is normally used from within the module\nthat implements the [Application](https://hexdocs.pm/elixir/Application.html#content)\nbehaviour or from one used to access configuration values, and has to be\ndefined in the following way:\n\n```elixir\ndefmodule MyConfig do\n  use AppConfig, otp_app: :my_app\n  # [...]\nend\n```\n\nThe `app` argument contains the name of the application where the functions\n(added by the macro from the [AppConfig](lib/app_config.ex) module) will look\nfor configuration parameters.\n\n\n## Installation\n\nThe package can be installed by adding `app_config` to your list of\ndependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:app_config, \"~\u003e 0.1.0\"}]\nend\n```\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nby running:\n\n    mix docs\n\nThe docs can also be found at [https://hexdocs.pm/app_config](https://hexdocs.pm/app_config).\n\n\n## Examples\n\nGiven the following application configuration:\n\n```elixir\nconfig :my_app,\n  db_host: {:system, \"DB_HOST\", \"localhost\"},\n  db_port: {:system, \"DB_PORT\", \"5432\"}\n  db_user: {:system, \"DB_USER\"},\n  db_password: {:system, \"DB_PASSWORD\"},\n  db_name: \"my_database\"\n```\n\nAnd the following environment variables:\n\n    export DB_USER=\"my_user\"\n    export DB_PASSWORD=\"guess_me\"\n\nAnd assuming that the `MyConfig` module is using the `AppConfig` macro, then\nthe following expressions used to retrieve the values of the parameters would\nbe valid:\n\n```elixir\n\"localhost\" = MyConfig.get_env(:db_host)\n5432 = MyConfig.get_env_integer(:db_port)\n{:ok, \"my_user\"} = MyConfig.fetch_env(:db_user)\n\"guess_me\" = MyConfig.fetch_env!(:db_password)\n\"my_database\" = MyConfig.get_env(:db_name, \"unknown\")\n```\n\nThe key can also be a list of atoms. The examples above could be converted to\nthe following format using a key that is actually a list:\n\n```elixir\nconfig :my_app, My.Database,\n  host: {:system, \"DB_HOST\", \"localhost\"},\n  port: {:system, \"DB_PORT\", 5432}\n  user: {:system, \"DB_USER\"},\n  password: {:system, \"DB_PASSWORD\"},\n  name: \"my_database\",\n  retry_interval: {:system, \"DB_RETRY_INTERVAL\", 0.5}\n  replication: {:system, \"DB_REPLICATION\", false}\n```\n\nTo retrieve the values, you'd then use the following code:\n\n```elixir\n\"localhost\" = MyConfig.get_env([My.Database, :host])\n5432 = MyConfig.get_env_integer([My.Database, :port])\n{:ok, \"my_user\"} = MyConfig.fetch_env([My.Database, :user])\n\"guess_me\" = MyConfig.fetch_env!([My.Database, :password])\n\"my_database\" = MyConfig.get_env([My.Database, :name], \"unknown\")\n```\n\nMost functions from the `AppConfig` module can also be called without using its\nmacro. To do so, just call the functions directly by passing the application's\nname as the first argument. e.g.\n\n```elixir\nAppConfig.get_env(:my_app, :db_host)\n```\n\nThis module will come in handy especially when retrieving configuration\nvalues for applications running within Elixir/Erlang releases, as it simplifies\nthe retrieval of values that were not defined when the release was built (i.e. at\ncompile-time) from OS environment variables.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcomellas%2Fapp_config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcomellas%2Fapp_config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcomellas%2Fapp_config/lists"}