mirror of
https://git.nerfingen.de/nerf/choirMail.git
synced 2025-05-15 17:50:31 +00:00
first working commit
This commit is contained in:
parent
2e2bbcd0d6
commit
0447d72e71
13 changed files with 465 additions and 0 deletions
29
app/Config.hs
Normal file
29
app/Config.hs
Normal file
|
@ -0,0 +1,29 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Config where
|
||||
|
||||
import qualified Toml
|
||||
import Toml(TomlCodec, (.=))
|
||||
import qualified Data.Text as T
|
||||
|
||||
data Config = Config {
|
||||
mailDomain :: String
|
||||
,mailUsername :: String
|
||||
,mailPassword :: String
|
||||
,mailTo :: T.Text
|
||||
,mailFrom :: 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
|
||||
|
||||
parseFile :: String -> IO (Either String Config)
|
||||
parseFile path = do
|
||||
config <- Toml.decodeFileEither configCodec path
|
||||
case config of
|
||||
Left errors -> return $ Left $ unwords $ fmap show errors
|
||||
Right x -> return $ Right $ x
|
Loading…
Add table
Add a link
Reference in a new issue