-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.hs
27 lines (23 loc) · 927 Bytes
/
Config.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Config ( Config(..)
, readConfig
) where
import Data.ConfigFile
import Data.Either.Utils
import Data.List.Split
data Config = Config { rpcuser :: String
, rpcpassword :: String
, rpchost :: String
, rpcport :: Int
} deriving (Show)
readConfig :: String -> IO Config
readConfig f = do
cp <- return . forceEither =<< readfile emptyCP f
return (Config { rpcuser = getSetting cp "rpcuser" ""
, rpcpassword = getSetting cp "rpcpassword" ""
, rpchost = getSetting cp "rpchost" "localhost"
, rpcport = getSetting cp "rpcport" 8336
})
where
getSetting cp x dfl = case get cp "DEFAULT" x of
Left _ -> dfl
Right x -> x