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" }