2016-01-10 15:39:55 +01:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
|
|
|
{-# LANGUAGE KindSignatures #-}
|
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
{-# LANGUAGE TypeOperators #-}
|
|
|
|
|
|
|
|
-- | This is a custom combinator for S.S.UsingConfigSpec. It's split up into
|
|
|
|
-- its own module to be able to test how exactly module import work when using
|
|
|
|
-- the config.
|
|
|
|
module Servant.Server.UsingConfigSpec.CustomCombinator where
|
|
|
|
|
|
|
|
import Servant
|
|
|
|
import Servant.Server.Internal.Config
|
|
|
|
import Servant.Server.Internal.RoutingApplication
|
|
|
|
|
2016-01-10 16:40:56 +01:00
|
|
|
data CustomCombinator (entryType :: *)
|
2016-01-10 15:39:55 +01:00
|
|
|
|
2016-01-10 16:40:56 +01:00
|
|
|
class ToCustomConfig entryType where
|
2016-01-10 16:50:17 +01:00
|
|
|
toCustomConfig :: entryType -> String
|
2016-01-10 15:39:55 +01:00
|
|
|
|
2016-01-10 16:50:17 +01:00
|
|
|
instance ToCustomConfig String where
|
2016-01-10 16:40:56 +01:00
|
|
|
toCustomConfig = id
|
|
|
|
|
|
|
|
instance forall subApi (c :: [*]) entryType .
|
|
|
|
(HasServer subApi, ToCustomConfig entryType) =>
|
|
|
|
HasServer (CustomCombinator entryType :> subApi) where
|
|
|
|
|
|
|
|
type ServerT (CustomCombinator entryType :> subApi) m =
|
2016-01-10 16:50:17 +01:00
|
|
|
String -> ServerT subApi m
|
2016-01-10 16:40:56 +01:00
|
|
|
type HasCfg (CustomCombinator entryType :> subApi) c =
|
|
|
|
(HasConfigEntry c entryType, HasCfg subApi c)
|
2016-01-10 15:39:55 +01:00
|
|
|
|
|
|
|
route Proxy config delayed =
|
|
|
|
route subProxy config (fmap (inject config) delayed :: Delayed (Server subApi))
|
|
|
|
where
|
|
|
|
subProxy :: Proxy subApi
|
|
|
|
subProxy = Proxy
|
|
|
|
|
2016-01-10 16:40:56 +01:00
|
|
|
inject config f = f (toCustomConfig (getConfigEntry config :: entryType))
|