Skip to content
Snippets Groups Projects
Commit a55e0ce9 authored by stuebinm's avatar stuebinm
Browse files

server: simple toml config

parent f10f80a2
No related branches found
No related tags found
No related merge requests found
port = 8080
tmpdir = "/tmp"
entrypoint = "main.json"
lintconfig = "./config.json"
......@@ -73,3 +73,4 @@ executables:
- containers
- microlens
- microlens-th
- tomland
......@@ -71,7 +71,6 @@ app config =
main :: IO ()
main = do
config' <- loadConfig "./config.toml"
state <- newMVar defaultState
let config = Config "/tmp" 8080 "main.json" "./config.json"
config' <- loadConfig config
run (port config) (app config' state)
run (port config') (app config' state)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
......@@ -23,6 +27,10 @@ import GHC.Generics (Generic)
import Lens.Micro (over)
import Lens.Micro.TH
import LintConfig (LintConfig')
import System.Exit.Compat (exitFailure)
import Toml (TomlCodec)
import qualified Toml
import Toml.Codec ((.=))
-- | a reference in a remote git repository
......@@ -36,14 +44,21 @@ type family ConfigRes (b :: Bool) a where
ConfigRes False a = FilePath
-- | the server's configuration
data Config l = Config
data Config (loaded :: Bool) = Config
{ tmpdir :: FilePath
-- ^ dir to clone git things in
, port :: Int
-- ^ port to bind to
, entrypoint :: FilePath
, lintconfig :: ConfigRes l LintConfig'
}
, lintconfig :: ConfigRes loaded LintConfig'
} deriving Generic
configCodec :: TomlCodec (Config False)
configCodec = Config
<$> Toml.string "tmpdir" .= tmpdir
<*> Toml.int "port" .= port
<*> Toml.string "entrypoint" .= entrypoint
<*> Toml.string "lintconfig" .= lintconfig
data JobStatus =
Pending | Linted DirResult | Failed Text
......@@ -59,9 +74,17 @@ makeLenses ''State
defaultState :: State
defaultState = State mempty mempty
loadConfig :: FilePath -> IO (Config True)
loadConfig path = do
res <- Toml.decodeFileEither configCodec path
case res of
Right config -> loadConfig' config
Left err -> do
print err
exitFailure
loadConfig :: Config False -> IO (Config True)
loadConfig config = do
loadConfig' :: Config False -> IO (Config True)
loadConfig' config = do
loaded <- LB.readFile (lintconfig config) >>= \res ->
case eitherDecode res :: Either String LintConfig' of
Left err -> error $ "config file invalid: " <> err
......
......@@ -88,6 +88,7 @@ executable server
, string-conversions
, text
, time
, tomland
, uuid
, wai
, walint
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment