Some cleanup

This commit is contained in:
Mats Rauhala 2021-10-27 21:10:22 +03:00
parent c200e5c98c
commit af538b9aa2
4 changed files with 19 additions and 17 deletions

View File

@ -1,8 +1,8 @@
module Main where module Main where
import qualified MyLib (someFunc) import qualified MyLib (defaultMain)
main :: IO () main :: IO ()
main = do main = do
putStrLn "Hello, Haskell!" putStrLn "Hello, Haskell!"
MyLib.someFunc MyLib.defaultMain

View File

@ -26,7 +26,7 @@ library
exposed-modules: MyLib exposed-modules: MyLib
Data.Config Data.Config
Data.Deriving.Aeson Data.Deriving.Aeson
Network.AMQP.Reddit Network.Reddit
Data.SubReddit Data.SubReddit
Publish Publish

View File

@ -1,32 +1,34 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module MyLib (someFunc) where module MyLib (defaultMain) where
import Control.Exception (bracket) import Control.Exception (bracket)
import Control.Lens import Control.Lens
import Data.Config
import qualified Data.Text.Strict.Lens as T
import Network.AMQP
import Network.AMQP.Reddit (publishEntries)
import Network.Wreq.Session (newSession)
import Data.Text (Text)
import qualified Data.ByteString.Lazy as LB
import Control.Monad (void) import Control.Monad (void)
import qualified Data.Aeson as A import qualified Data.Aeson as A
import Data.Functor.Contravariant ((>$<)) import qualified Data.ByteString.Lazy as LB
import Publish (Publish(..)) import Data.Config
import Data.Foldable (for_) import Data.Foldable (for_)
import Data.Functor.Contravariant ((>$<))
import Data.Text (Text)
import qualified Data.Text.Strict.Lens as T
import Network.AMQP
import Network.Reddit (publishEntries)
import Network.Wreq.Session (newSession)
import Publish (Publish(..))
amqpPublisher :: Channel -> Text -> Publish IO LB.ByteString amqpPublisher :: Channel -> Text -> Publish IO LB.ByteString
amqpPublisher channel exchange = Publish $ \lbs -> void $ publishMsg channel exchange "" (message lbs) amqpPublisher channel exchange = Publish $ \lbs ->
void $ publishMsg channel exchange routingKey (message lbs)
where where
routingKey = "doesn't matter on fanout"
message lbs = newMsg message lbs = newMsg
{ msgBody = lbs { msgBody = lbs
, msgDeliveryMode = Just Persistent , msgDeliveryMode = Just Persistent
} }
someFunc :: IO () defaultMain :: IO ()
someFunc = do defaultMain = do
conf <- readConfig "./config.dhall" conf <- readConfig "./config.dhall"
let connect = openConnection let connect = openConnection
(conf ^. amqp . host . T.unpacked) (conf ^. amqp . host . T.unpacked)

View File

@ -5,7 +5,7 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module Network.AMQP.Reddit where module Network.Reddit where
import Control.Lens import Control.Lens
import Data.Aeson (FromJSON, ToJSON, Value) import Data.Aeson (FromJSON, ToJSON, Value)