diff options
Diffstat (limited to 'src/server/Config.hs')
-rw-r--r-- | src/server/Config.hs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/server/Config.hs b/src/server/Config.hs new file mode 100644 index 0000000..f4144f7 --- /dev/null +++ b/src/server/Config.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE FlexibleContexts #-} + +module Config + ( getConfig + , Config(..) + ) where + +import Data.ConfigFile +import Data.Text (Text) +import qualified Data.Text as T + +import Control.Monad.Trans.Error (runErrorT) +import Control.Monad.IO.Class (liftIO) +import Control.Monad (join) +import Control.Arrow (left) +import Control.Applicative (liftA2) + +data Config = Config + { hostname :: Text + , port :: Int + } deriving (Read, Eq, Show) + +getConfig :: FilePath -> IO (Either String Config) +getConfig filePath = + left show <$> (runErrorT $ do + cp <- join $ liftIO $ readfile emptyCP filePath + liftA2 + Config + (T.pack <$> get cp "DEFAULT" "hostname") + (get cp "DEFAULT" "port") + ) |