| Copyright | (c) 2019 Daniel YU |
|---|---|
| License | BSD3 |
| Maintainer | leptonyu@gmail.com |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Yam
Contents
Description
A out-of-the-box wrapper of servant,
providing configuration loader salak and flexible extension with AppMiddleware.
Synopsis
- start :: forall file api cxt. (HasLoad file, HasLogger cxt, HasSalaks cxt, HasServer api cxt, HasSwagger api) => String -> file -> Version -> AppMiddleware Simple cxt -> Proxy api -> ServerT api (AppV cxt IO) -> IO ()
- start' :: forall api cxt. (HasLogger cxt, HasSalaks cxt, HasServer api cxt, HasSwagger api) => LoadSalak () -> Version -> AppMiddleware Simple cxt -> Proxy api -> ServerT api (AppV cxt IO) -> IO ()
- serveWarp :: AppConfig -> Application -> IO ()
- data AppConfig = AppConfig {}
- data AppT cxt m a
- type AppV cxt = AppT (VaultHolder ': cxt)
- type AppIO cxt = AppT cxt IO
- type AppSimple = AppV Simple IO
- type Simple = '[SourcePack, LogFuncHolder]
- runAppT :: Context cxt -> AppT cxt m a -> m a
- runVault :: MonadIO m => Context cxt -> Vault -> AppV cxt IO a -> m a
- throwS :: (HasCallStack, MonadIO m, MonadLogger m) => ServerError -> Text -> m a
- newtype AppMiddleware a b = AppMiddleware {
- runAM :: Context a -> Middleware -> IO HealthResult -> (Context b -> Middleware -> IO HealthResult -> LoggingT IO ()) -> LoggingT IO ()
- emptyAM :: AppMiddleware cxt cxt
- simpleContext :: a -> AppMiddleware cxt (a ': cxt)
- simpleConfig :: (HasSalaks cxt, FromProp (AppT cxt (LoggingT IO)) a) => Text -> AppMiddleware cxt (a ': cxt)
- simpleConfig' :: (HasSalaks cxt, FromProp (AppT cxt (LoggingT IO)) a) => Text -> (a -> AppT cxt (LoggingT IO) b) -> AppMiddleware cxt (b ': cxt)
- simpleMiddleware :: Middleware -> AppMiddleware cxt cxt
- data HealthStatus
- data HealthResult = HealthResult {}
- mergeHealth :: IO HealthStatus -> Text -> IO HealthResult -> IO HealthResult
- data LogConfig = LogConfig {}
- type HasLogger cxt = (HasContextEntry cxt LogFuncHolder, TryContextEntry cxt VaultHolder)
- data LogFuncHolder
- data VaultHolder
- data Context (contextTypes :: [Type]) where
- class HasContextEntry (context :: [Type]) val where
- getContextEntry :: Context context -> val
- class TryContextEntry (cxt :: [*]) (entry :: *) where
- tryContextEntry :: Context cxt -> Maybe entry
- getEntry :: (HasContextEntry cxt entry, Monad m) => AppT cxt m entry
- tryEntry :: (TryContextEntry cxt entry, Monad m) => AppT cxt m (Maybe entry)
- type HasSalaks cxt = HasContextEntry cxt SourcePack
- data SwaggerConfig = SwaggerConfig {}
- serveWithContextAndSwagger :: forall api context. (HasSwagger api, HasServer api context) => SwaggerConfig -> (Swagger -> Swagger) -> Proxy api -> Context context -> ServerT api Handler -> Application
- baseInfo :: String -> Text -> Version -> Int -> Swagger -> Swagger
- data SwaggerTag (name :: Symbol) (desp :: Symbol)
- spanNoNotifier :: Span -> AppV cxt IO ()
- data Span = Span {
- spanId :: ByteString
- name :: Text
- startTime :: Int
- finishTime :: Maybe Int
- tags :: HashMap Text SpanTag
- logs :: HashMap Text Text
- context :: SpanContext
- references :: [SpanReference]
- data SpanContext = SpanContext {}
- data SpanTag
- data SpanReference = SpanReference {
- referenceType :: SpanReferenceType
- parentId :: ByteString
- showText :: Show a => a -> Text
- randomString :: IO ByteString
- randomCode :: Vector Char -> Int -> IO String
- decodeUtf8 :: ByteString -> Text
- encodeUtf8 :: Text -> ByteString
- pack :: String -> Text
- liftIO :: MonadIO m => IO a -> m a
- fromMaybe :: a -> Maybe a -> a
- throw :: Exception e => e -> a
- logInfo :: (HasCallStack, MonadLogger m) => Text -> m ()
- logError :: (HasCallStack, MonadLogger m) => Text -> m ()
- logWarn :: (HasCallStack, MonadLogger m) => Text -> m ()
- logDebug :: (HasCallStack, MonadLogger m) => Text -> m ()
How to use this library
import Salak.Yaml import Servant import Yam import Data.Version type API = "hello" :> Get '[PlainText] Text service :: ServerT API AppSimple service = return "world" main = start "app" YAML (makeVersion []) (return emptyAM) (Proxy @API) (return service)
Yam Server
Arguments
| :: (HasLoad file, HasLogger cxt, HasSalaks cxt, HasServer api cxt, HasSwagger api) | |
| => String | File config name |
| -> file | Config file format |
| -> Version | Version |
| -> AppMiddleware Simple cxt | Application Middleware |
| -> Proxy api | Application API Proxy |
| -> ServerT api (AppV cxt IO) | Application API Server |
| -> IO () |
Standard Starter of Yam.
start' :: forall api cxt. (HasLogger cxt, HasSalaks cxt, HasServer api cxt, HasSwagger api) => LoadSalak () -> Version -> AppMiddleware Simple cxt -> Proxy api -> ServerT api (AppV cxt IO) -> IO () Source #
Standard Starter of Yam.
Application Configuration
Application Configuration.
Constructors
| AppConfig | |
Application Context
Application Context Monad.
Instances
| MonadTrans (AppT cxt) Source # | |
| Monad m => MonadReader (Context cxt) (AppT cxt m) Source # | |
| Monad m => Monad (AppT cxt m) Source # | |
| Functor m => Functor (AppT cxt m) Source # | |
| Applicative m => Applicative (AppT cxt m) Source # | |
| MonadIO m => MonadIO (AppT cxt m) Source # | |
| MonadUnliftIO m => MonadUnliftIO (AppT cxt m) Source # | |
| MonadThrow m => MonadThrow (AppT cxt m) Source # | |
| MonadCatch m => MonadCatch (AppT cxt m) Source # | |
| (HasLogger cxt, MonadIO m) => HasValid (AppT cxt m) Source # | |
| (HasLogger cxt, MonadIO m) => MonadLogger (AppT cxt m) Source # | |
| (HasLogger cxt, MonadIO m) => MonadLoggerIO (AppT cxt m) Source # | |
| (HasContextEntry cxt SourcePack, Monad m) => MonadSalak (AppT cxt m) Source # | |
type Simple = '[SourcePack, LogFuncHolder] Source #
Simple Application context
runVault :: MonadIO m => Context cxt -> Vault -> AppV cxt IO a -> m a Source #
Run Application with Vault.
Arguments
| :: (HasCallStack, MonadIO m, MonadLogger m) | |
| => ServerError | Server error |
| -> Text | message |
| -> m a |
throw ServerError with message
Application Middleware
newtype AppMiddleware a b Source #
Application Middleware.
Constructors
| AppMiddleware | |
Fields
| |
Instances
| Category AppMiddleware Source # | |
Defined in Yam.Middleware Methods id :: AppMiddleware a a # (.) :: AppMiddleware b c -> AppMiddleware a b -> AppMiddleware a c # | |
emptyAM :: AppMiddleware cxt cxt Source #
Empty Application Middleware.
simpleContext :: a -> AppMiddleware cxt (a ': cxt) Source #
Simple Application Middleware, just provide a config to context.
simpleConfig :: (HasSalaks cxt, FromProp (AppT cxt (LoggingT IO)) a) => Text -> AppMiddleware cxt (a ': cxt) Source #
Simple Application Middleware, just provide a config to context.
simpleConfig' :: (HasSalaks cxt, FromProp (AppT cxt (LoggingT IO)) a) => Text -> (a -> AppT cxt (LoggingT IO) b) -> AppMiddleware cxt (b ': cxt) Source #
Simple Application Middleware, just provide a config to context.
simpleMiddleware :: Middleware -> AppMiddleware cxt cxt Source #
Simple Application Middleware, promote a Middleware to AppMiddleware
Health
data HealthStatus Source #
Instances
| Eq HealthStatus Source # | |
Defined in Yam.Server.Health | |
| Show HealthStatus Source # | |
Defined in Yam.Server.Health Methods showsPrec :: Int -> HealthStatus -> ShowS # show :: HealthStatus -> String # showList :: [HealthStatus] -> ShowS # | |
| Generic HealthStatus Source # | |
Defined in Yam.Server.Health Associated Types type Rep HealthStatus :: Type -> Type # | |
| ToJSON HealthStatus Source # | |
Defined in Yam.Server.Health Methods toJSON :: HealthStatus -> Value # toEncoding :: HealthStatus -> Encoding # toJSONList :: [HealthStatus] -> Value # toEncodingList :: [HealthStatus] -> Encoding # | |
| ToSchema HealthStatus Source # | |
Defined in Yam.Server.Health Methods declareNamedSchema :: Proxy HealthStatus -> Declare (Definitions Schema) NamedSchema # | |
| type Rep HealthStatus Source # | |
data HealthResult Source #
Constructors
| HealthResult | |
Fields
| |
Instances
mergeHealth :: IO HealthStatus -> Text -> IO HealthResult -> IO HealthResult Source #
Modules
Logger
Logger config
Constructors
| LogConfig | |
type HasLogger cxt = (HasContextEntry cxt LogFuncHolder, TryContextEntry cxt VaultHolder) Source #
Context with logger.
data LogFuncHolder Source #
Holder for LogFunc
data VaultHolder Source #
Holder for Vault
Context
data Context (contextTypes :: [Type]) where #
Contexts are used to pass values to combinators. (They are not meant
to be used to pass parameters to your handlers, i.e. they should not replace
any custom ReaderT-monad-stack that you're using
with hoistServer.) If you don't use combinators that
require any context entries, you can just use serve as always.
If you are using combinators that require a non-empty Context you have to
use serveWithContext and pass it a Context that contains all
the values your combinators need. A Context is essentially a heterogenous
list and accessing the elements is being done by type (see getContextEntry).
The parameter of the type Context is a type-level list reflecting the types
of the contained context entries. To create a Context with entries, use the
operator (::.)
>>>:type True :. () :. EmptyContextTrue :. () :. EmptyContext :: Context '[Bool, ()]
Constructors
| EmptyContext :: forall (contextTypes :: [Type]). Context ([] :: [Type]) | |
| (:.) :: forall (contextTypes :: [Type]) x (xs :: [Type]). x -> Context xs -> Context (x ': xs) infixr 5 |
class HasContextEntry (context :: [Type]) val where #
This class is used to access context entries in Contexts. getContextEntry
returns the first value where the type matches:
>>>getContextEntry (True :. False :. EmptyContext) :: BoolTrue
If the Context does not contain an entry of the requested type, you'll get
an error:
>>>getContextEntry (True :. False :. EmptyContext) :: String... ...No instance for (HasContextEntry '[] [Char]) ...
Methods
getContextEntry :: Context context -> val #
Instances
| HasContextEntry xs val => HasContextEntry (notIt ': xs) val | |
Defined in Servant.Server.Internal.Context Methods getContextEntry :: Context (notIt ': xs) -> val # | |
| HasContextEntry (val ': xs) val | |
Defined in Servant.Server.Internal.Context Methods getContextEntry :: Context (val ': xs) -> val # | |
class TryContextEntry (cxt :: [*]) (entry :: *) where Source #
This class provide a optional supports for get entry from Context.
Methods
tryContextEntry :: Context cxt -> Maybe entry Source #
Instances
| TryContextEntry a entry Source # | |
Defined in Yam.Prelude Methods tryContextEntry :: Context a -> Maybe entry Source # | |
| TryContextEntry (entry ': as) entry Source # | |
Defined in Yam.Prelude Methods tryContextEntry :: Context (entry ': as) -> Maybe entry Source # | |
| TryContextEntry as entry => TryContextEntry (a ': as) entry Source # | |
Defined in Yam.Prelude Methods tryContextEntry :: Context (a ': as) -> Maybe entry Source # | |
tryEntry :: (TryContextEntry cxt entry, Monad m) => AppT cxt m (Maybe entry) Source #
Try get entry from AppT
Configuration
type HasSalaks cxt = HasContextEntry cxt SourcePack Source #
Swagger
data SwaggerConfig Source #
Swagger Configuration
Constructors
| SwaggerConfig | |
Instances
| Eq SwaggerConfig Source # | |
Defined in Yam.Swagger Methods (==) :: SwaggerConfig -> SwaggerConfig -> Bool # (/=) :: SwaggerConfig -> SwaggerConfig -> Bool # | |
| Show SwaggerConfig Source # | |
Defined in Yam.Swagger Methods showsPrec :: Int -> SwaggerConfig -> ShowS # show :: SwaggerConfig -> String # showList :: [SwaggerConfig] -> ShowS # | |
| MonadCatch m => FromProp m SwaggerConfig Source # | |
Defined in Yam.Swagger Methods fromProp :: Prop m SwaggerConfig # | |
serveWithContextAndSwagger Source #
Arguments
| :: (HasSwagger api, HasServer api context) | |
| => SwaggerConfig | Swagger configuration. |
| -> (Swagger -> Swagger) | Swagger modification. |
| -> Proxy api | Application API Proxy. |
| -> Context context | Application context. |
| -> ServerT api Handler | Application API Server |
| -> Application |
Serve with swagger.
Arguments
| :: String | Hostname |
| -> Text | Server Name |
| -> Version | Server version |
| -> Int | Port |
| -> Swagger | Old swagger |
| -> Swagger |
Swagger modification
data SwaggerTag (name :: Symbol) (desp :: Symbol) Source #
Instances
| HasClient m api => HasClient m (SwaggerTag name desp :> api) Source # | |
Defined in Yam.Swagger Associated Types type Client m (SwaggerTag name desp :> api) :: Type # Methods clientWithRoute :: Proxy m -> Proxy (SwaggerTag name desp :> api) -> Request -> Client m (SwaggerTag name desp :> api) # hoistClientMonad :: Proxy m -> Proxy (SwaggerTag name desp :> api) -> (forall x. mon x -> mon' x) -> Client mon (SwaggerTag name desp :> api) -> Client mon' (SwaggerTag name desp :> api) # | |
| (HasSwagger api, KnownSymbol name, KnownSymbol desp) => HasSwagger (SwaggerTag name desp :> api :: Type) Source # | |
Defined in Yam.Swagger | |
| HasServer api ctx => HasServer (SwaggerTag name desp :> api :: Type) ctx Source # | |
Defined in Yam.Swagger Associated Types type ServerT (SwaggerTag name desp :> api) m :: Type # Methods route :: Proxy (SwaggerTag name desp :> api) -> Context ctx -> Delayed env (Server (SwaggerTag name desp :> api)) -> Router env # hoistServerWithContext :: Proxy (SwaggerTag name desp :> api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (SwaggerTag name desp :> api) m -> ServerT (SwaggerTag name desp :> api) n # | |
| type Client m (SwaggerTag name desp :> api) Source # | |
Defined in Yam.Swagger | |
| type ServerT (SwaggerTag name desp :> api :: Type) m Source # | |
Defined in Yam.Swagger | |
Reexport
Constructors
| Span | |
Fields
| |
data SpanContext Source #
Constructors
| SpanContext | |
Instances
| Eq SpanContext Source # | |
Defined in Data.Opentracing.Types | |
| Show SpanContext Source # | |
Defined in Data.Opentracing.Types Methods showsPrec :: Int -> SpanContext -> ShowS # show :: SpanContext -> String # showList :: [SpanContext] -> ShowS # | |
data SpanReference Source #
Constructors
| SpanReference | |
Fields
| |
Instances
| Eq SpanReference Source # | |
Defined in Data.Opentracing.Types Methods (==) :: SpanReference -> SpanReference -> Bool # (/=) :: SpanReference -> SpanReference -> Bool # | |
| Show SpanReference Source # | |
Defined in Data.Opentracing.Types Methods showsPrec :: Int -> SpanReference -> ShowS # show :: SpanReference -> String # showList :: [SpanReference] -> ShowS # | |
randomString :: IO ByteString Source #
Utility
decodeUtf8 :: ByteString -> Text #
Decode a ByteString containing UTF-8 encoded text that is known
to be valid.
If the input contains any invalid UTF-8 data, an exception will be
thrown that cannot be caught in pure code. For more control over
the handling of invalid data, use decodeUtf8' or
decodeUtf8With.
encodeUtf8 :: Text -> ByteString #
Encode text using UTF-8 encoding.
fromMaybe :: a -> Maybe a -> a #
The fromMaybe function takes a default value and and Maybe
value. If the Maybe is Nothing, it returns the default values;
otherwise, it returns the value contained in the Maybe.
Examples
Basic usage:
>>>fromMaybe "" (Just "Hello, World!")"Hello, World!"
>>>fromMaybe "" Nothing""
Read an integer from a string using readMaybe. If we fail to
parse an integer, we want to return 0 by default:
>>>import Text.Read ( readMaybe )>>>fromMaybe 0 (readMaybe "5")5>>>fromMaybe 0 (readMaybe "")0
throw :: Exception e => e -> a #
Throw an exception. Exceptions may be thrown from purely
functional code, but may only be caught within the IO monad.
logInfo :: (HasCallStack, MonadLogger m) => Text -> m () #
See logDebug
Since: monad-logger-0.3.19
logError :: (HasCallStack, MonadLogger m) => Text -> m () #
See logDebug
Since: monad-logger-0.3.19
logWarn :: (HasCallStack, MonadLogger m) => Text -> m () #
See logDebug
Since: monad-logger-0.3.19
logDebug :: (HasCallStack, MonadLogger m) => Text -> m () #
Logs a message with the location provided by
an implicit CallStack.
Since: monad-logger-0.3.19