Skip to content
Configuration management with yaml
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src/Data/Yaml
tests
.ghci
.gitignore
.travis.yml
LICENSE
README.lhs
README.md
Setup.hs
stack.yaml
yaml-config.cabal

README.md

yaml-config Build Status

Load, parse and find fields in YAML config files.

Example

YAML config

server:
    port: 8080
    logs:
        access: /var/log/server/access.log
        error:  /var/log/server/error.log

Haskell source

{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}

module Main where
import Prelude hiding (lookup)
import Data.Word (Word16)
import Data.Yaml.Config (load, subconfig, lookupDefault, lookup)

main :: IO ()
main = do
    config <- load "./example.yaml"

    serverConfig <- subconfig "server" config
    let interface = lookupDefault "interface" "127.0.0.1" serverConfig
        port :: Word16 = lookupDefault "port" 80 serverConfig

    logConfig <- subconfig "logs" serverConfig
    accessLog <- lookup "access" logConfig
    errorLog <- lookup "error" logConfig

    mapM_ putStrLn [interface, (show port), errorLog, accessLog]

Result

$ ./server
127.0.0.1
8080
/var/log/server/error.log
/var/log/server/access.log

Links

Hackage

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.