{-# LANGUAGE DeriveGeneric #-} module Config ( loadConfig, Config (serve, plausible), Serve (port, baseUrl, templateDir), Plausible (queryUrl, token, siteId), ) where import GHC.Generics (Generic) import Data.Aeson (FromJSON, eitherDecodeFileStrict) data Config = Config { serve :: !Serve, plausible :: !Plausible } deriving (Generic) data Serve = Serve { port :: !Int, baseUrl :: !String, templateDir :: !String } deriving (Generic) data Plausible = Plausible { queryUrl :: !String, token :: !String, siteId :: !String } deriving (Generic) instance FromJSON Config where instance FromJSON Serve where instance FromJSON Plausible where loadConfig :: FilePath -> IO Config loadConfig path = loadConfig' =<< eitherDecodeFileStrict path where loadConfig' :: Either String Config -> IO Config loadConfig' (Left err) = fail err loadConfig' (Right config) = return config