From 985974c264804ff788b3b5242fef707d4b7fa9a6 Mon Sep 17 00:00:00 2001 From: evuez Date: Mon, 1 Apr 2024 15:17:30 +0200 Subject: Initial commit --- app/Main.hs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/Main.hs (limited to 'app') diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..e82d838 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,44 @@ +module Main (main) where + +import qualified Cache +import Control.Concurrent (forkIO) +import qualified Http +import Intro +import qualified Queue as Q +import qualified Smtp +import System.Environment (getArgs) + +data Opts = Opts {httpPort :: String, smtpPort :: String} deriving (Show) + +defaultHttpPort :: String +defaultHttpPort = "9785" + +defaultSmtpPort :: String +defaultSmtpPort = "5879" + +main :: IO () +main = do + args <- getArgs + case (parseArgs args) of + Right opts -> do + putStrLn $ "Starting HTTP server at http://localhost:" ++ opts.httpPort + putStrLn $ "Starting SMTP server at smtp://localhost:" ++ opts.smtpPort + + queue <- Q.newQueue + cache <- Cache.newInMemory + _ <- forkIO $ Cache.start queue cache + _ <- forkIO $ Http.runServer Nothing opts.httpPort cache queue + Smtp.runServer Nothing opts.smtpPort queue + Left err -> putStrLn ("Error. " ++ err) + +parseArgs :: [String] -> Either String Opts +parseArgs args = parse args (Opts defaultHttpPort defaultSmtpPort) + where + parse [] opts = Right opts + parse (x1 : x2 : xs) opts + | x1 == "-http-port" = parse xs (opts{httpPort = x2}) + | x1 == "-smtp-port" = parse xs (opts{smtpPort = x2}) + parse (x : []) _ + | x == "-http-port" = Left "Missing HTTP port" + | x == "-smtp-port" = Left "Missing SMTP port" + parse (x : _) _ = Left ("Unrecognized option: " ++ x) -- cgit v1.2.3