]> average.org Git - pdns-pipe-nmc.git/commitdiff
separate config module
authorEugene Crosser <crosser@average.org>
Thu, 27 Mar 2014 21:49:49 +0000 (01:49 +0400)
committerEugene Crosser <crosser@average.org>
Thu, 27 Mar 2014 21:49:49 +0000 (01:49 +0400)
Config.hs [new file with mode: 0644]
pdns-pipe-nmc.hs

diff --git a/Config.hs b/Config.hs
new file mode 100644 (file)
index 0000000..070b422
--- /dev/null
+++ b/Config.hs
@@ -0,0 +1,27 @@
+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
+
index ba6289944877d8e464d70afbe55ab2ba6f65a8b6..d37491114a9adbc91091b26a95bd1ba4b86f60eb 100644 (file)
@@ -2,45 +2,23 @@
 
 module Main where
 
---import Control.Applicative
 import Control.Monad
 import qualified Data.ByteString.Char8 as C (pack, unpack)
 import qualified Data.ByteString.Lazy.Char8 as L (pack, unpack)
 import Data.ByteString.Lazy as BS hiding (reverse, putStrLn)
-import Data.ConfigFile
-import Data.Either.Utils
 import Data.List.Split
 import Data.Aeson (encode, decode, Value(..))
 import Network.HTTP.Types
 import Data.Conduit
 import Network.HTTP.Conduit
 import Data.JsonRpcClient
+
+import Config
 import PowerDns
 import NmcJson
 
 confFile = "/etc/namecoin.conf"
 
--- Config file handling
-
-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
-
 -- HTTP/JsonRpc interface
 
 qReq :: Config -> ByteString -> ByteString -> Request m