conferer-provider-json-0.1.0.4: Configuration for reading json files

Safe HaskellNone
LanguageHaskell2010

Conferer.Provider.JSON

Contents

Synopsis

How to use this provider

As any other provider you can add it to a config using the addProvider function. There are a couple of oddities that come from supporting many different providers which do not support numbers, arrays or objects nativelly

import Conferer
import Conferer.Provider.JSON (mkJsonProvider)

main = do
  config <-
    defaultConfig "awesomeapp"
    & addProvider mkJsonProvider
  warpSettings <- getFromConfig "warp" config
  runSettings warpSettings application

This will result on a provider that upon starting looks the file config/{.env}.json in the current directory and uses it to provide config keys.

TODO Describe how we transform json into key value strings

mkJsonProvider :: ProviderCreator Source #

Default ProviderCreator which usese files with config/{env}.json template, if the file is not present it will behave like the null provider (it has no keys) but if the file doesn't have valid json it will throw an error

mkJsonProvider' :: Value -> ProviderCreator Source #

Just like mkJsonProvider but accepts the json value as a parameter

Internal utility functions

These may be useful for someone but are subject to change at any point so use with care

traverseJSON :: Key -> Value -> Maybe Text Source #

Traverse a Value using a Key to get a value for conferer (Text).

This function can nest objects and arrays when keys are nested

traverseJSON "a.b" {a: {b: 12}} == Just "12"
traverseJSON "a.b" {a: {b: false}} == Just "false"
traverseJSON "a" {a: {b: false}} == Nothing
traverseJSON "1" [false, true] == Just "true"
traverseJSON "0.a" [{a: "hi"}] == Just "hi"
traverseJSON "0" [] == Nothing

resultToMaybe :: Result a -> Maybe a Source #

Because we use an old version of aeson