summaryrefslogtreecommitdiffstats
path: root/src/Main/Config.hs
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-11-06 16:10:43 +0100
committertv <tv@shackspace.de>2014-11-06 16:10:43 +0100
commit9b2bea53c6bc87be639964aaca87c09ab16df486 (patch)
tree5bd768ccc901a357fbbf77ab337b2015eb486646 /src/Main/Config.hs
parent781e26234dd1854c51895fa4fcc31f26f209c52f (diff)
Flush log after each request.
Diffstat (limited to 'src/Main/Config.hs')
-rw-r--r--src/Main/Config.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Main/Config.hs b/src/Main/Config.hs
index 9639faa..66f72ea 100644
--- a/src/Main/Config.hs
+++ b/src/Main/Config.hs
@@ -20,7 +20,11 @@ import Text.Read (readEither)
data Config = Config
{ cgroupRoot :: FilePath
+ -- ^ Mount point of the cgroup root.
, httpPort :: Port
+ -- ^ TCP port number for cgserver to bind to.
+ , flushLog :: Bool
+ -- ^ Whether to flush the logging buffer after each request.
}
deriving Show
@@ -33,12 +37,14 @@ data Config = Config
--
-- > cgroupRoot = "/sys/fs/cgroup"
-- > httpPort = 8001
+-- > flushLog = True
--
defaultConfig :: IO Config
defaultConfig =
Config
<$> getEnv' Right "/sys/fs/cgroup" "cgroupRoot"
<*> getEnv' readEither 8001 "httpPort"
+ <*> getEnv' readBool True "flushLog"
-- | Takes a parse function, a default value, and a variable name.
@@ -53,3 +59,11 @@ getEnv' pf def name =
error $ "Main.Config.getEnv' " <> show name <> ": " <> err
Right value ->
value
+
+
+-- | Read a JSON-style boolean ("true", "false").
+readBool :: String -> Either String Bool
+readBool x = case x of
+ "true" -> Right True
+ "false" -> Right False
+ _ -> Left $ "not a bool: " <> x