initial commit
This commit is contained in:
commit
a60daddd0c
11 changed files with 333 additions and 0 deletions
25
src/Config.hs
Normal file
25
src/Config.hs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{-# 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue