choirMail/app/Config.hs
2022-11-12 16:18:11 +01:00

32 lines
931 B
Haskell

{-# LANGUAGE OverloadedStrings #-}
module Config where
import qualified Toml
import Toml(TomlCodec, (.=))
import qualified Data.Text as T
import Monad
data Config = Config {
mailDomain :: String
,mailUsername :: String
,mailPassword :: String
,mailTo :: T.Text
,mailFrom :: T.Text
,mailErrorTo :: T.Text
} deriving Show
configCodec :: TomlCodec Config
configCodec = Config
<$> Toml.string "mailDomain" .= mailDomain
<*> Toml.string "mailUser" .= mailUsername
<*> Toml.string "mailPassword" .= mailPassword
<*> Toml.text "mailTo" .= mailTo
<*> Toml.text "mailFrom" .= mailFrom
<*> Toml.text "mailErrorTo" .= mailErrorTo
parseConfigFile :: (MonadIO m, MonadFail m) => String -> m Config
parseConfigFile path = do
config <- liftIO $ Toml.decodeFileEither configCodec path
case config of
Left errors -> fail $ unwords $ fmap show errors
Right x -> return x