aboutsummaryrefslogtreecommitdiffstats
path: root/src/Reaktor/Config.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2019-01-23 00:02:42 +0100
committertv <tv@krebsco.de>2019-01-23 00:57:36 +0100
commitd40815fd56bf1895af89b72b1171675a2e0ae5f7 (patch)
tree83b96a701f16b13915836c3a6c94463732a9f6d8 /src/Reaktor/Config.hs
parenta00da57346c195b1b15d1c6aca2891483901aae6 (diff)
src: use more simple functionsv0.1.0
Diffstat (limited to 'src/Reaktor/Config.hs')
-rw-r--r--src/Reaktor/Config.hs76
1 files changed, 0 insertions, 76 deletions
diff --git a/src/Reaktor/Config.hs b/src/Reaktor/Config.hs
deleted file mode 100644
index 908f9a8..0000000
--- a/src/Reaktor/Config.hs
+++ /dev/null
@@ -1,76 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-module Reaktor.Config where
-
-import Data.Aeson
-import qualified Data.HashMap.Lazy as HML
-import qualified Data.Text as T
-import Reaktor.Internal
-import qualified Reaktor.Plugins
-
-
-instance FromJSON Config where
- parseJSON (Object v) = do
- p <- v .:? "port" .!= defaultPort
-
- Config
- <$> v .: "hostname"
- <*> pure p
- <*> v .: "nick"
- <*> v .:? "useTLS" .!= (p == tlsPort)
- <*> v .:? "logTime" .!= True
- <*> v .:? "plugins" .!= []
- parseJSON _ = pure undefined
-
-
-data Config = Config {
- hostname :: HostName,
- port :: ServiceName,
- nick :: Nickname,
- useTLS :: Bool,
- logTime :: Bool,
- pluginInstances :: [PluginInstance]
- }
-
-
-addPlugin :: T.Text -> IO Plugin -> Config -> Config
-addPlugin name p r =
- r { pluginInstances = pluginInstances r <> [PluginInstance name (Left p)] }
-
-
-defaultPort :: ServiceName
-defaultPort = tlsPort
-
-tlsPort :: ServiceName
-tlsPort = "6697"
-
-
-data PluginInstance = PluginInstance {
- pi_name :: T.Text,
- pi_plugin :: Either (IO Plugin) Plugin
- }
-
-instance FromJSON PluginInstance where
- parseJSON o@(Object v) =
- case HML.lookup "plugin" v of
- Just (String name) -> do
- let p = Reaktor.Plugins.get name
- c = HML.lookupDefault (Object HML.empty) "config" v
- pure $ PluginInstance name (Left $ p c)
- Just _ -> error ("bad plugin object: " <> show o)
- _ -> error ("mising 'plugin' attribute: " <> show o)
- parseJSON x =
- error ("bad plugin type: " <> show x)
-
-
-initPlugins :: Config -> IO Config
-initPlugins cfg = do
- plugins' <- mapM initPlugin (pluginInstances cfg)
- return cfg { pluginInstances = plugins' }
- where
- initPlugin :: PluginInstance -> IO PluginInstance
- initPlugin i = do
- p <-
- case pi_plugin i of
- Right p -> return p
- Left f -> f
- return i { pi_plugin = Right p }