Dhall configuration
This commit is contained in:
parent
6d08e9dad4
commit
7c08c46c16
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
dist/
|
dist/
|
||||||
|
config/config.dhall
|
||||||
|
8
config/config.dhall.sample
Normal file
8
config/config.dhall.sample
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
database = {
|
||||||
|
username = "username"
|
||||||
|
, password = "password"
|
||||||
|
, host = "hostname"
|
||||||
|
, database = "ebook"
|
||||||
|
}
|
||||||
|
}
|
10
config/devel.dhall
Normal file
10
config/devel.dhall
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
-- Devel configuration file, with defaults for local testing environment
|
||||||
|
-- pre-filled
|
||||||
|
{
|
||||||
|
database = {
|
||||||
|
username = "postgres"
|
||||||
|
, password = "devel"
|
||||||
|
, host = "localhost"
|
||||||
|
, database = "postgres"
|
||||||
|
}
|
||||||
|
}
|
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:9.6.1
|
||||||
|
environment:
|
||||||
|
- POSTGRES_PASSWORD=devel
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
@ -18,8 +18,9 @@ cabal-version: >=1.10
|
|||||||
executable ebook-manager
|
executable ebook-manager
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
other-modules: Devel.Main
|
other-modules: Devel.Main
|
||||||
, Server
|
|
||||||
, API
|
, API
|
||||||
|
, Configuration
|
||||||
|
, Server
|
||||||
, Types
|
, Types
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
build-depends: base >=4.10 && <4.11
|
build-depends: base >=4.10 && <4.11
|
||||||
@ -45,5 +46,7 @@ executable ebook-manager
|
|||||||
, dhall
|
, dhall
|
||||||
, lucid
|
, lucid
|
||||||
, servant-lucid
|
, servant-lucid
|
||||||
|
, lens
|
||||||
|
, generic-lens
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
19
src/Configuration.hs
Normal file
19
src/Configuration.hs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{-# Language NoImplicitPrelude #-}
|
||||||
|
{-# Language DeriveGeneric #-}
|
||||||
|
{-# Language DuplicateRecordFields #-}
|
||||||
|
module Configuration where
|
||||||
|
|
||||||
|
import ClassyPrelude
|
||||||
|
import Dhall (Interpret)
|
||||||
|
|
||||||
|
data Pg = Pg { username :: Text
|
||||||
|
, password :: Text
|
||||||
|
, host :: Text
|
||||||
|
, database :: Text }
|
||||||
|
deriving (Show, Generic)
|
||||||
|
|
||||||
|
|
||||||
|
newtype Config = Config { database :: Pg } deriving (Show, Generic)
|
||||||
|
|
||||||
|
instance Interpret Pg
|
||||||
|
instance Interpret Config
|
@ -1,3 +1,4 @@
|
|||||||
|
{-# Language OverloadedStrings #-}
|
||||||
module Devel.Main where
|
module Devel.Main where
|
||||||
|
|
||||||
import Main (defaultMain)
|
import Main (defaultMain)
|
||||||
@ -6,6 +7,7 @@ import Control.Monad (void)
|
|||||||
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
|
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
|
||||||
import Foreign.Store (Store(..), lookupStore, readStore, storeAction, withStore)
|
import Foreign.Store (Store(..), lookupStore, readStore, storeAction, withStore)
|
||||||
import GHC.Word (Word32)
|
import GHC.Word (Word32)
|
||||||
|
import Dhall (input, auto)
|
||||||
|
|
||||||
update :: IO ()
|
update :: IO ()
|
||||||
update = do
|
update = do
|
||||||
@ -23,7 +25,7 @@ update = do
|
|||||||
withStore doneStore takeMVar
|
withStore doneStore takeMVar
|
||||||
readStore doneStore >>= start
|
readStore doneStore >>= start
|
||||||
start :: MVar () -> IO ThreadId
|
start :: MVar () -> IO ThreadId
|
||||||
start done = forkFinally defaultMain (\_ -> putMVar done ())
|
start done = forkFinally (input auto "./config/devel.dhall" >>= defaultMain) (\_ -> putMVar done ())
|
||||||
|
|
||||||
modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO ()
|
modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO ()
|
||||||
modifyStoredIORef store f = withStore store $ \ref -> do
|
modifyStoredIORef store f = withStore store $ \ref -> do
|
||||||
|
11
src/Main.hs
11
src/Main.hs
@ -1,11 +1,16 @@
|
|||||||
|
{-# Language OverloadedStrings #-}
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Server (server)
|
import Server (server)
|
||||||
import Network.Wai.Handler.Warp (run)
|
import Network.Wai.Handler.Warp (run)
|
||||||
import Types
|
import Types
|
||||||
|
import Configuration (Config)
|
||||||
|
import Dhall (input, auto)
|
||||||
|
|
||||||
defaultMain :: IO ()
|
defaultMain :: Config -> IO ()
|
||||||
defaultMain = run 8080 (server App)
|
defaultMain c = run 8080 (server (App c))
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = defaultMain
|
main = do
|
||||||
|
c <- input auto "./config/config.dhall"
|
||||||
|
defaultMain c
|
||||||
|
@ -3,7 +3,8 @@ module Types where
|
|||||||
|
|
||||||
import ClassyPrelude
|
import ClassyPrelude
|
||||||
import Control.Monad.Logger
|
import Control.Monad.Logger
|
||||||
|
import Configuration
|
||||||
|
|
||||||
data App = App
|
newtype App = App { config :: Config }
|
||||||
|
|
||||||
type AppM = LoggingT (ReaderT App IO)
|
type AppM = LoggingT (ReaderT App IO)
|
||||||
|
Loading…
Reference in New Issue
Block a user