bartfrenk / easy-conf

Extensible configuration language for Haskell programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data.Config: Extensible configuration language

Description

Simple configuration language for Haskell programs based on YAML and inspired by EDN.

Example

Given a file test.yaml with the following content:

web:
  port: $env(PORT) or 8000
  host: localhost

The program:

import           Data.Aeson
import qualified Data.ByteString    as B
import           System.Environment (setEnv)

import           Data.Config (decodeWithDefault)

data Settings = Settings
  { host :: String
  , port :: Maybe Int
  } deriving (Eq, Show, Generic)

instance FromJSON Settings

readSettings :: IO Settings
readSettings = do
  setEnv "PORT" "5000"
  bs <- B.readFile "test.yaml"
  decodeWithDefault bs

main :: IO ()
main = readSettings >>= print

prints:

Settings { port = Just 5000, host = "localhost" }

About

Extensible configuration language for Haskell programs

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Haskell 100.0%