Copyright | (c) 2019 Lucas David Traverso |
---|---|
License | MPL-2.0 |
Maintainer | Lucas David Traverso <lucas6246@gmail.com> |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Public and stable API for the most basic usage of this library
Synopsis
- mkConfig :: Text -> IO Config
- mkConfig' :: Defaults -> [SourceCreator] -> IO Config
- fetch :: forall a. (FromConfig a, Typeable a, DefaultConfig a) => Config -> IO a
- fetch' :: forall a. (FromConfig a, Typeable a) => Config -> a -> IO a
- fetchKey :: forall a. (FromConfig a, Typeable a) => Config -> Key -> a -> IO a
- fetchFromConfig :: forall a. (FromConfig a, Typeable a) => Key -> Config -> IO a
- safeFetchKey :: forall a. (FromConfig a, Typeable a) => Config -> Key -> IO (Maybe a)
- unsafeFetchKey :: forall a. (FromConfig a, Typeable a) => Config -> Key -> IO a
- class DefaultConfig a where
- configDef :: a
- class FromConfig a
- data Config
- data Key
How to use this doc
This doc is mostly for reference, so you probably won't learn how to use conferer by reading it. For more detailed and guided documentation the best place is the webpage: https://conferer.ludat.io/docs
Creating a Config
mkConfig :: Text -> IO Config Source #
Create a Config
which reads from command line arguments, env vars and
property files that depend on the environment (config/development.properties
)
by default
mkConfig' :: Defaults -> [SourceCreator] -> IO Config Source #
Create a Config
with the given defaults and source creators.
The sources will take precedence by the order they have in the list (earlier in
the list means it's tried first).
If the requested key is not found in any source it'll be looked up in the defaults.
Getting values from a config
These functions allow you to get any type that implements FromConfig
fetch :: forall a. (FromConfig a, Typeable a, DefaultConfig a) => Config -> IO a Source #
Use the FromConfig
instance to get a value of type a
from the config
using some default fallback. The most common use for this is creating a custom
record and using this function to fetch it at initialization time.
This function throws only parsing exceptions when the values are present
but malformed somehow ("abc"
as an Int) but that depends on the FromConfig
implementation for the type.
fetchFromConfig :: forall a. (FromConfig a, Typeable a) => Key -> Config -> IO a Source #
safeFetchKey :: forall a. (FromConfig a, Typeable a) => Config -> Key -> IO (Maybe a) Source #
unsafeFetchKey :: forall a. (FromConfig a, Typeable a) => Config -> Key -> IO a Source #
Same as fetchKey
but it throws when the value isn't present.
class DefaultConfig a where Source #
Utility only typeclass to smooth the naming differences between default values for external library settings
This typeclass is not used internally it's only here for convinience for users
class FromConfig a Source #
The typeclass for defining the way to get values from a Config
, hiding the
Text
based nature of the Source
s and parse whatever value
as the types sees fit
Some of these instances are provided in different packages to avoid the heavy dependencies.
It provides a reasonable default using Generic
s so most of the time user need
not to implement this typeclass.
Instances
Some useful types
This type acts as the entry point for most of the library, it's main purpouse
is to expose a uniform interface into multiple configuration sources (such as
env vars, cli args, and many others including use defined ones using the
Source
interface)
This type is used extensivelly as a way to point into a Source
and in turn into a Config
. The intended way to create them is
is using mkKey
.
It's a list of alphanumeric words and each Source
can interpret
it as it sees fit.