diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-25 18:26:24 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-25 18:26:24 +0000 |
commit | 02c9b435266fe2d738ca9ee17963351a44b89a39 (patch) | |
tree | 218c2610e7b0b2aa9b6256634677564068bbf015 /server/src | |
parent | e9cc80873498ba63469f9730d79846e5944aba06 (diff) | |
download | thermoprint-02c9b435266fe2d738ca9ee17963351a44b89a39.tar thermoprint-02c9b435266fe2d738ca9ee17963351a44b89a39.tar.gz thermoprint-02c9b435266fe2d738ca9ee17963351a44b89a39.tar.bz2 thermoprint-02c9b435266fe2d738ca9ee17963351a44b89a39.tar.xz thermoprint-02c9b435266fe2d738ca9ee17963351a44b89a39.zip |
minor code cleanup
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/Thermoprint/Server.hs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/server/src/Thermoprint/Server.hs b/server/src/Thermoprint/Server.hs index 3d0e97e..7767c12 100644 --- a/server/src/Thermoprint/Server.hs +++ b/server/src/Thermoprint/Server.hs | |||
@@ -64,6 +64,13 @@ instance Default Config where | |||
64 | , printers = Map.empty | 64 | , printers = Map.empty |
65 | } | 65 | } |
66 | 66 | ||
67 | withPrinters :: MonadResource m => Config -> [m PrinterMethod] -> m Config | ||
68 | -- ^ Add a list of printers to a 'Config' | ||
69 | withPrinters cfg pss = (\map -> cfg { printers = map }) <$> foldlM (\map spec -> Map.insert (nextKey map) <$> printer spec <*> pure map) Map.empty pss | ||
70 | where | ||
71 | nextKey map | ||
72 | | Map.null map = 0 | ||
73 | | otherwise = succ . fst $ Map.findMin map | ||
67 | 74 | ||
68 | thermoprintServer :: ( MonadLoggerIO m | 75 | thermoprintServer :: ( MonadLoggerIO m |
69 | , MonadReader ConnectionPool m | 76 | , MonadReader ConnectionPool m |
@@ -83,10 +90,3 @@ thermoprintServer io = Dyre.wrapMain $ Dyre.defaultParams | |||
83 | mapM_ ($(logWarnS) "DB") =<< runSqlPool (runMigrationSilent migrateAll) =<< ask | 90 | mapM_ ($(logWarnS) "DB") =<< runSqlPool (runMigrationSilent migrateAll) =<< ask |
84 | forM_ printers $ resourceForkIO . runPrinter | 91 | forM_ printers $ resourceForkIO . runPrinter |
85 | liftIO . Warp.runSettings warpSettings . serve thermoprintAPI . flip enter API.thermoprintServer =<< handlerNat printers | 92 | liftIO . Warp.runSettings warpSettings . serve thermoprintAPI . flip enter API.thermoprintServer =<< handlerNat printers |
86 | |||
87 | withPrinters :: MonadResource m => Config -> [m PrinterMethod] -> m Config | ||
88 | withPrinters cfg pss = (\map -> cfg { printers = map }) <$> foldlM (\map spec -> Map.insert (nextKey map) <$> printer spec <*> pure map) Map.empty pss | ||
89 | where | ||
90 | nextKey map | ||
91 | | Map.null map = 0 | ||
92 | | otherwise = succ . fst $ Map.findMin map | ||