Skip to content
envconfig provides a function to get config objects from environment variables.
Nim
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
src
tests
.gitignore
.monit.yml
README.rst
envconfig.nimble

README.rst

envconfig

nimble-version nimble-install nimble-docs gh-actions

envconfig provides a function to get config objects from environment variables. envconfig is inspired by Go envconfig.

Installation

nimble install envconfig

Usage

Basic

Example that setting environment variables with shell.

export MYAPP_NAME=envconfig
export MYAPP_VERSION=v1.0.0
export MYAPP_DIR=/opt/envconfig
export MYAPP_PORT=1234
export MYAPP_DEV=true
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.

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.

API Documents

LICENSE

MIT

You can’t perform that action at this time.