aboutsummaryrefslogtreecommitdiff
path: root/src/server/Config.hs
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-08-08 19:50:58 +0200
committerJoris Guyonvarch2015-08-08 19:50:58 +0200
commita4f60df0f3b72553380bdd3ca960abf42048ed7e (patch)
treecf30e45801e68129eb7b1c990b142a412fa98e30 /src/server/Config.hs
parentcd7ca2fcc7a2f4a10235f8807a89c8d6549b99bf (diff)
downloadbudget-a4f60df0f3b72553380bdd3ca960abf42048ed7e.tar.gz
budget-a4f60df0f3b72553380bdd3ca960abf42048ed7e.tar.bz2
budget-a4f60df0f3b72553380bdd3ca960abf42048ed7e.zip
Getting the hostname and the port in config file
Diffstat (limited to 'src/server/Config.hs')
-rw-r--r--src/server/Config.hs31
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")
+ )