git.iko.soy/typeable/servant
on master help sign in
Rename one function, run custom monad code from main
commit5620d2d781b80d47b5de0e1150b2ca04d28f8c3e authorKostiantyn Rybnikov <k-bx@k-bx.com> dateMon 22 Oct 2018, 14:09 (8 years ago) parentc1e15ef
2 files changed+8−15
doc/cookbook/generic/Generic.lhs+5−12 servant-server/src/Servant/Server/Generic.hs+3−3
doc/cookbook/generic/Generic.lhs+5−12
@@ -5,7 +5,7 @@
55{-# LANGUAGE DeriveGeneric #-}
66{-# LANGUAGE RankNTypes #-}
77{-# LANGUAGE TypeOperators #-}
8−module Main (main, api, getLink, routesLinks, cliGet, mainMyMonad) where
8+module Main (main, api, getLink, routesLinks, cliGet) where
99
1010import Control.Exception (throwIO)
1111import Data.Proxy (Proxy (..))
@@ -102,6 +102,10 @@ main = do
102102 ("run":_) -> do
103103 putStrLn "Starting cookbook-generic at http://localhost:8000"
104104 run 8000 app
105+ -- see this cookbook below for custom-monad explanation
106+ ("run-custom-monad":_) -> do
107+ putStrLn "Starting cookbook-generic with a custom monad at http://localhost:8000"
108+ run 8000 (appMyMonad AppCustomState)
105109 _ -> putStrLn "To run, pass 'run' argument: cabal new-run cookbook-generic run"
106110```
107111
@@ -134,14 +138,3 @@ nt s x = runReaderT x s
134138
135139appMyMonad :: AppCustomState -> Application
136140appMyMonad state = genericServeT (nt state) recordMyMonad
137−
138−mainMyMonad :: IO ()
139−mainMyMonad = do
140− args <- getArgs
141− case args of
142− ("run":_) -> do
143− putStrLn "Starting cookbook-generic at http://localhost:8000"
144− run 8000 (appMyMonad AppCustomState)
145− _ ->
146− putStrLn "To run, pass 'run' argument: cabal new-run cookbook-generic run"
147−```
servant-server/src/Servant/Server/Generic.hs+3−3
@@ -13,7 +13,7 @@ module Servant.Server.Generic (
1313 AsServer,
1414 genericServe,
1515 genericServeT,
16− genericServeT',
16+ genericServeTWithContext,
1717 genericServer,
1818 genericServerT,
1919 ) where
@@ -62,7 +62,7 @@ genericServeT f server = serve p $ hoistServer p f (genericServerT server)
6262-- while using the given 'Context' to serve the application (contexts are typically
6363-- used by auth-related combinators in servant, e.g to hold auth checks) and the given
6464-- transformation to map all the handlers back to the 'Handler' monad.
65−genericServeT'
65+genericServeTWithContext
6666 :: forall (routes :: * -> *) (m :: * -> *) (ctx :: [*]).
6767 ( GenericServant routes (AsServerT m)
6868 , GenericServant routes AsApi
@@ -73,7 +73,7 @@ genericServeT'
7373 -> routes (AsServerT m) -- ^ your record full of request handlers
7474 -> Context ctx -- ^ the 'Context' to serve the application with
7575 -> Application
76−genericServeT' f server ctx =
76+genericServeTWithContext f server ctx =
7777 serveWithContext p ctx $
7878 hoistServerWithContext p pctx f (genericServerT server)
7979 where