No description
Find a file
2024-07-06 11:29:11 +09:00
.github/workflows fix: with 2024-07-06 11:29:11 +09:00
src change error type: Defect -> CatchableError 2020-06-07 05:22:42 +00:00
tests chore: Test with Nim 2.0 (#5) 2023-08-06 23:18:22 +09:00
.gitignore chore: change test code from 'unittest' to 'testament' (#3) 2021-03-13 19:29:35 +09:00
.monit.yml Implemented basic functions 2020-01-02 18:42:05 +09:00
envconfig.nimble change error type: Defect -> CatchableError 2020-06-07 05:22:42 +00:00
README.rst Remove nimble badges 2023-08-06 23:24:44 +09:00

#########
envconfig
#########

|gh-actions|

envconfig provides a function to get config objects from environment variables.
envconfig is inspired by `Go envconfig <https://github.com/kelseyhightower/envconfig>`_.

.. contents:: Table of contents
   :depth: 3

************
Installation
************

.. code-block:: Bash

   nimble install envconfig

*****
Usage
*****

-----
Basic
-----

Example that setting environment variables with shell.

.. code-block:: Bash

   export MYAPP_NAME=envconfig
   export MYAPP_VERSION=v1.0.0
   export MYAPP_DIR=/opt/envconfig
   export MYAPP_PORT=1234
   export MYAPP_DEV=true

.. code-block:: Nim

   import envconfig

   type
     MyApp = object
       name, version, dir: string
       port: int
       dev: bool

   let config = getEnvConfig(MyApp)

   echo "MYAPP_NAME: " & config.name       # envconfig
   echo "MYAPP_VERSION: " & config.version # v1.0.0
   echo "MYAPP_DIR: " & config.dir         # /opt/envconfig
   echo "MYAPP_PORT: " & $config.port      # 1234
   echo "MYAPP_DEV: " & $config.dev        # true

Example that setting environment variables with Nim.

.. code-block:: Nim

  import envconfig
  from os import putEnv

  type
    MyApp = object
      name, version, dir: string
      port: int
      dev: bool

  putEnv("MYAPP_NAME", "envconfig")
  putEnv("MYAPP_VERSION", "v1.0.0")
  putEnv("MYAPP_DIR", "/opt/envconfig")
  putEnv("MYAPP_PORT", "1234")
  putEnv("MYAPP_DEV", "true")

  let config = getEnvConfig(MyApp)

  echo "MYAPP_NAME: " & config.name       # envconfig
  echo "MYAPP_VERSION: " & config.version # v1.0.0
  echo "MYAPP_DIR: " & config.dir         # /opt/envconfig
  echo "MYAPP_PORT: " & $config.port      # 1234
  echo "MYAPP_DEV: " & $config.dev        # true

----------
Validation
----------

Provides tiny functions to validate values.
A procedure can validate `requires`, `min value`, `max value` and `regex match`.
For more informations, see also `API documents <https://jiro4989.github.io/envconfig/envconfig.html>`_.

*************
API Documents
*************

* `envconfig <https://jiro4989.github.io/envconfig/envconfig.html>`_

*******
LICENSE
*******

MIT

.. |gh-actions| image:: https://github.com/jiro4989/envconfig/workflows/build/badge.svg
   :target: https://github.com/jiro4989/envconfig/actions