Commit 51fce3ac authored by MrMan's avatar MrMan

Set up machinery to use config from main

parent bf66ff3a
......@@ -2,13 +2,17 @@
module Main where
import Config (AppConfig, Host, Port, ProcessEnvironment(..), makeAppConfig)
import Data.Functor.Identity
import Config (AppConfig(..), EntityStoreConfig, Host, Port, ProcessEnvironment(..), makeAppConfig)
import Control.Monad (join)
import Data.Semigroup ((<>))
import Types
import Util (rightOrThrow)
import Lib
import Options.Applicative
import System.Environment (getEnvironment)
import Text.Pretty.Simple (pPrint)
import Components.EntityStore.SQLite
data Options = Options
{ cfgPath :: Maybe FilePath
......@@ -59,12 +63,22 @@ showConfig Options{cfgPath=path} = pullEnvironment
runServer :: Options -> IO ()
runServer Options{cfgPath=path} = pullEnvironment
>>= makeAppConfig path
>> server
>>= rightOrThrow
>>= server
-- | Start up the server and serve requests
server :: IO ()
server = putStrLn "<SERVER START>"
-- | Build an entity store for use in the main application
buildEntityStore :: Complete EntityStoreConfig -> IO SQLiteEntityStore
buildEntityStore cfg = putStrLn "[info] initializing EntityStore with config:"
>> pPrint cfg
>> (construct cfg :: IO (Either EntityStoreError SQLiteEntityStore))
>>= rightOrThrow
-- | Start up the server and serve requests
server :: Complete AppConfig -> IO ()
server cfg = buildEntityStore entityStoreCfg
>>= \entityStore -> putStrLn "<SERVER START>"
where
entityStoreCfg = runIdentity $ entityStoreConfig cfg
main :: IO ()
main = parseOptions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment