From 0be357bb60a2bc4523056aba34add78b715211f5 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 19 Dec 2023 13:08:22 -0500 Subject: Add fig-frontend --- fig-frontend/src/Fig/Frontend/Utils.hs | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 fig-frontend/src/Fig/Frontend/Utils.hs (limited to 'fig-frontend/src/Fig/Frontend/Utils.hs') diff --git a/fig-frontend/src/Fig/Frontend/Utils.hs b/fig-frontend/src/Fig/Frontend/Utils.hs new file mode 100644 index 0000000..1ba1d5f --- /dev/null +++ b/fig-frontend/src/Fig/Frontend/Utils.hs @@ -0,0 +1,37 @@ +{-# Language RecordWildCards #-} +{-# Language ApplicativeDo #-} + +module Fig.Frontend.Utils + ( FigFrontendException(..) + , loadConfig + , Config(..) + , module Network.HTTP.Types.Status + ) where + +import Fig.Prelude + +import Network.HTTP.Types.Status + +import qualified Toml + +newtype FigFrontendException = FigFrontendException Text + deriving (Show, Eq, Ord) +instance Exception FigFrontendException + +data Config = Config + { port :: Int + , assetPath :: FilePath + , clientId :: Text + } deriving (Show, Eq, Ord) + +configCodec :: Toml.TomlCodec Config +configCodec = do + port <- Toml.int "port" Toml..= (\a -> a.port) + assetPath <- Toml.string "asset_path" Toml..= (\a -> a.assetPath) + clientId <- Toml.text "client_id" Toml..= (\a -> a.clientId) + pure $ Config{..} + +loadConfig :: FilePath -> IO Config +loadConfig path = Toml.decodeFileEither configCodec path >>= \case + Left err -> throwM . FigFrontendException $ tshow err + Right config -> pure config -- cgit v1.2.3