From af538b9aa2817a6ec645c37e4620503fe549dec8 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Wed, 27 Oct 2021 21:10:22 +0300 Subject: [PATCH] Some cleanup --- app/Main.hs | 4 ++-- reddit-pub.cabal | 2 +- src/MyLib.hs | 28 +++++++++++++++------------- src/Network/{AMQP => }/Reddit.hs | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) rename src/Network/{AMQP => }/Reddit.hs (98%) diff --git a/app/Main.hs b/app/Main.hs index 60d904e..0238396 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,8 +1,8 @@ module Main where -import qualified MyLib (someFunc) +import qualified MyLib (defaultMain) main :: IO () main = do putStrLn "Hello, Haskell!" - MyLib.someFunc + MyLib.defaultMain diff --git a/reddit-pub.cabal b/reddit-pub.cabal index 329fef6..5036f21 100644 --- a/reddit-pub.cabal +++ b/reddit-pub.cabal @@ -26,7 +26,7 @@ library exposed-modules: MyLib Data.Config Data.Deriving.Aeson - Network.AMQP.Reddit + Network.Reddit Data.SubReddit Publish diff --git a/src/MyLib.hs b/src/MyLib.hs index 4b3cf9f..168348e 100644 --- a/src/MyLib.hs +++ b/src/MyLib.hs @@ -1,32 +1,34 @@ {-# LANGUAGE OverloadedStrings #-} -module MyLib (someFunc) where +module MyLib (defaultMain) where import Control.Exception (bracket) 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 qualified Data.Aeson as A -import Data.Functor.Contravariant ((>$<)) -import Publish (Publish(..)) +import qualified Data.ByteString.Lazy as LB +import Data.Config 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 exchange = Publish $ \lbs -> void $ publishMsg channel exchange "" (message lbs) +amqpPublisher channel exchange = Publish $ \lbs -> + void $ publishMsg channel exchange routingKey (message lbs) where + routingKey = "doesn't matter on fanout" message lbs = newMsg { msgBody = lbs , msgDeliveryMode = Just Persistent } -someFunc :: IO () -someFunc = do +defaultMain :: IO () +defaultMain = do conf <- readConfig "./config.dhall" let connect = openConnection (conf ^. amqp . host . T.unpacked) diff --git a/src/Network/AMQP/Reddit.hs b/src/Network/Reddit.hs similarity index 98% rename from src/Network/AMQP/Reddit.hs rename to src/Network/Reddit.hs index 18e65fd..a744122 100644 --- a/src/Network/AMQP/Reddit.hs +++ b/src/Network/Reddit.hs @@ -5,7 +5,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeOperators #-} -module Network.AMQP.Reddit where +module Network.Reddit where import Control.Lens import Data.Aeson (FromJSON, ToJSON, Value)