Copyright | 2019 Daniel YU |
---|---|
License | MIT |
Maintainer | leptonyu@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
A quick out-of-box factory using to build application with many useful builtin components, based on boots.
- Builtin configuration, use salak.
- Builtin logger functions, use fast-logger as backend.
- Builtin health check, support health check registration.
- Builtin random support, use splitmix as backend.
- Define standard application values, such that
name
,version
.
Synopsis
- bootApp :: String -> Version -> Factory IO (AppEnv ()) env -> Factory IO (AppEnv env) (IO ()) -> IO ()
- data AppT env m a
- type App env = AppT env IO
- runAppT :: env -> AppT env m a -> m a
- withAppT :: (env -> env) -> AppT env m a -> AppT env m a
- class Monad m => MonadReader r (m :: Type -> Type) | m -> r where
- asks :: MonadReader r m => (r -> a) -> m a
- natA :: MonadMask m => Factory (AppT env m) env component -> Factory m env component
- delay :: MonadMask m => AppT env m () -> Factory m env ()
- produceA :: MonadMask m => AppT env m res -> (res -> AppT env m ()) -> Factory m env res
- class HasApp env ext where
- data AppEnv ext = AppEnv {}
- askExt :: Lens' (AppEnv ext) ext
- buildApp :: (MonadIO m, MonadMask m) => String -> Version -> ParseCommandLine -> ext -> Factory m () (AppEnv ext)
- class HasSalak env where
- class Monad m => MonadSalak (m :: Type -> Type) where
- askSourcePack :: m SourcePack
- askReload :: m (IO ReloadResult)
- setLogF :: (CallStack -> Text -> IO ()) -> m ()
- logSalak :: Text -> m ()
- require :: (MonadThrow m, MonadIO m, FromProp m a) => Text -> m a
- buildSalak :: (MonadIO m, MonadCatch m) => String -> Factory m () Salak
- tryBuildByKey :: (MonadMask m, MonadIO m, HasSalak env) => Bool -> Text -> Factory m env () -> Factory m env ()
- class HasLogger env where
- data LogConfig = LogConfig {}
- data LogFunc = LogFunc {}
- addTrace :: ToLogStr msg => msg -> LogFunc -> LogFunc
- buildLogger :: (MonadIO m, MonadMask m, HasSalak env) => Text -> Factory m env LogFunc
- logTrace :: (MonadLog e m, HasCallStack) => LogStr -> m ()
- logDebug :: (MonadLog e m, HasCallStack) => LogStr -> m ()
- logInfo :: (MonadLog e m, HasCallStack) => LogStr -> m ()
- logWarn :: (MonadLog e m, HasCallStack) => LogStr -> m ()
- logError :: (MonadLog e m, HasCallStack) => LogStr -> m ()
- logFatal :: (MonadLog e m, HasCallStack) => LogStr -> m ()
- logCS :: CallStack -> LogLevel -> LogStr -> LogFunc -> IO ()
- data LogLevel
- levelFromStr :: Text -> Either String LogLevel
- class ToLogStr msg where
- data LogStr
- data Health = Health {}
- data HealthStatus
- class HasHealth env where
- emptyHealth :: IO Health
- registerHealth :: (MonadMask n, HasHealth env) => Text -> IO HealthStatus -> Factory n env ()
- newtype RD = RD {}
- class HasRandom env where
- class Monad m => MonadRandom env m | m -> env where
- newRD :: RDType -> IO RD
- data RDType
- makeRD :: SMGen -> IO RD
- makeRD0 :: SMGen -> (RD -> IO a) -> IO a
- forkRD :: RD -> IO RD
- hex32 :: IsString a => Word64 -> a
- hex64 :: IsString a => Word64 -> a
- nextWord64 :: SMGen -> (Word64, SMGen)
- splitSMGen :: SMGen -> (SMGen, SMGen)
- data CLI = CLI {}
- interruptCli :: MonadThrow m => m a
- runCLI :: Version -> (ParseCommandLine -> IO ()) -> IO ()
- module Control.Monad.Factory
- rightToMaybe :: Either a b -> Maybe b
- whenJust :: Applicative f => Maybe a -> (a -> f ()) -> f ()
- mapLeft :: (a -> c) -> Either a b -> Either c b
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- class IsString a where
- fromString :: String -> a
- view :: Getting a s a -> s -> a
- over :: ASetter s t a b -> (a -> b) -> s -> t
- type Lens' s a = Lens s s a a
- lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- (&) :: a -> (a -> b) -> b
- class Semigroup a => Monoid a where
- data Proxy (t :: k) :: forall k. k -> Type = Proxy
- class Default a where
- def :: a
Environment
:: String | name |
-> Version | version |
-> Factory IO (AppEnv ()) env | Generate env |
-> Factory IO (AppEnv env) (IO ()) | Application body. |
-> IO () |
An out-of-box application booter, with builtin components. Also supports a default commandline handling.
Monad App
Application monad transformation.
Instances
Monad m => MonadReader env (AppT env m) Source # | |
(HasRandom env, MonadIO n) => MonadRandom env (AppT env n) Source # | |
MonadTrans (AppT env) Source # | |
Defined in Boots.App.Internal | |
Monad m => Monad (AppT env m) Source # | |
Functor m => Functor (AppT env m) Source # | |
Applicative m => Applicative (AppT env m) Source # | |
Defined in Boots.App.Internal | |
MonadIO m => MonadIO (AppT env m) Source # | |
Defined in Boots.App.Internal | |
MonadMask m => MonadMask (AppT env m) Source # | |
Defined in Boots.App.Internal | |
MonadCatch m => MonadCatch (AppT env m) Source # | |
MonadThrow m => MonadThrow (AppT env m) Source # | |
Defined in Boots.App.Internal | |
MonadUnliftIO m => MonadUnliftIO (AppT env m) Source # | |
Defined in Boots.App.Internal | |
(HasSalak env, Monad m) => MonadSalak (AppT env m) Source # | |
Defined in Boots.Factory.Salak |
withAppT :: (env -> env) -> AppT env m a -> AppT env m a Source #
Execute a computation in a modified environment.
class Monad m => MonadReader r (m :: Type -> Type) | m -> r where #
See examples in Control.Monad.Reader.
Note, the partially applied function type (->) r
is a simple reader monad.
See the instance
declaration below.
Retrieves the monad environment.
:: (r -> r) | The function to modify the environment. |
-> m a |
|
-> m a |
Executes a computation in a modified environment.
:: (r -> a) | The selector function to apply to the environment. |
-> m a |
Retrieves a function of the current environment.
Instances
:: MonadReader r m | |
=> (r -> a) | The selector function to apply to the environment. |
-> m a |
Retrieves a function of the current environment.
Utilities
natA :: MonadMask m => Factory (AppT env m) env component -> Factory m env component Source #
Nature transform from AppT
env
m
to m
.
delay :: MonadMask m => AppT env m () -> Factory m env () Source #
Add a delayed action into the factory.
produceA :: MonadMask m => AppT env m res -> (res -> AppT env m ()) -> Factory m env res Source #
Produce res
under environment env
.
Factory Instances
Application
Application environment.
buildApp :: (MonadIO m, MonadMask m) => String -> Version -> ParseCommandLine -> ext -> Factory m () (AppEnv ext) Source #
Factory used to build AppEnv
.
Configuration
class Monad m => MonadSalak (m :: Type -> Type) where #
Core type class of salak, which provide function to parse properties.
askSourcePack :: m SourcePack #
Monad has the ability to get a SourcePack instance.
askReload :: m (IO ReloadResult) #
Get reload action which used for reload profiles
setLogF :: (CallStack -> Text -> IO ()) -> m () #
require :: (MonadThrow m, MonadIO m, FromProp m a) => Text -> m a #
Parse properties using FromProp
. For example:
a :: Bool <- require "bool.key" b :: Maybe Int <- require "int.optional.key" c :: Either String Int <- require "int.error.key" d :: IO Int <- require "int.reloadable.key"
require
supports parse IO
values, which actually wrap a MVar
variable and can be reseted by reloading configurations.
Normal value will not be affected by reloading configurations.
Instances
buildSalak :: (MonadIO m, MonadCatch m) => String -> Factory m () Salak Source #
Factory which loads configurations, and produces a configuration instance.
Utilities
:: (MonadMask m, MonadIO m, HasSalak env) | |
=> Bool | Default value. |
-> Text | Configuration key. |
-> Factory m env () | Target factory. |
-> Factory m env () | Launch the target factory if configuration is setted to be true. |
A helper function used for try to build a factory if configuration set true.
Logger
A closable logging function. Also supporting change log level and count failed logs.
buildLogger :: (MonadIO m, MonadMask m, HasSalak env) => Text -> Factory m env LogFunc Source #
Factory which produces a LogFunc
.
Log Functions
logTrace :: (MonadLog e m, HasCallStack) => LogStr -> m () Source #
Logs a LevelTrace
message.
logDebug :: (MonadLog e m, HasCallStack) => LogStr -> m () Source #
Logs a LevelDebug
message.
logError :: (MonadLog e m, HasCallStack) => LogStr -> m () Source #
Logs a LevelError
message.
logFatal :: (MonadLog e m, HasCallStack) => LogStr -> m () Source #
Logs a LevelFatal
message.
logCS :: CallStack -> LogLevel -> LogStr -> LogFunc -> IO () Source #
Logs a message with location given by CallStack
.
Log level.
Reexport log functions
Types that can be converted to a LogStr
. Instances for
types from the text
library use a UTF-8 encoding. Instances
for numerical types use a decimal encoding.
Instances
Log message builder. Use (<>
) to append two LogStr in O(1).
Components
Health Check
Health detail.
Instances
Eq Health Source # | |
Show Health Source # | |
Generic Health Source # | |
HasHealth (IO Health) Source # | |
type Rep Health Source # | |
Defined in Boots.Health type Rep Health = D1 (MetaData "Health" "Boots.Health" "boots-app-0.2.0.1-Kg6LM9U8tYyBUPFnxuhaBl" False) (C1 (MetaCons "Health" PrefixI True) (S1 (MetaSel (Just "status") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 HealthStatus) :*: (S1 (MetaSel (Just "errMsg") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe Text)) :*: S1 (MetaSel (Just "details") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (HashMap Text Health))))) |
data HealthStatus Source #
Health status.
Instances
Eq HealthStatus Source # | |
Defined in Boots.Health (==) :: HealthStatus -> HealthStatus -> Bool # (/=) :: HealthStatus -> HealthStatus -> Bool # | |
Show HealthStatus Source # | |
Defined in Boots.Health showsPrec :: Int -> HealthStatus -> ShowS # show :: HealthStatus -> String # showList :: [HealthStatus] -> ShowS # | |
Generic HealthStatus Source # | |
Defined in Boots.Health type Rep HealthStatus :: Type -> Type # from :: HealthStatus -> Rep HealthStatus x # to :: Rep HealthStatus x -> HealthStatus # | |
type Rep HealthStatus Source # | |
emptyHealth :: IO Health Source #
Default health detail.
:: (MonadMask n, HasHealth env) | |
=> Text | Component name. |
-> IO HealthStatus | Check action. |
-> Factory n env () |
Register a health checker.
Random value generator.
class Monad m => MonadRandom env m | m -> env where Source #
Seed container type.
nextWord64 :: SMGen -> (Word64, SMGen) #
Generate a Word64
.
>>>
take 3 $ map (printf "%x") $ unfoldr (Just . nextWord64) (mkSMGen 1337) :: [String]
["b5c19e300e8b07b3","d600e0e216c0ac76","c54efc3b3cc5af29"]
splitSMGen :: SMGen -> (SMGen, SMGen) #
Split a generator into a two uncorrelated generators.
CLI
interruptCli :: MonadThrow m => m a Source #
Normal interrupt cli.
Reexport
module Control.Monad.Factory
rightToMaybe :: Either a b -> Maybe b Source #
whenJust :: Applicative f => Maybe a -> (a -> f ()) -> f () Source #
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).
fromString :: String -> a #
Instances
view :: Getting a s a -> s -> a #
>>>
view _1 (1, 2)
1
The reason it's not in Lens.Micro is that view
in lens has a more general signature:
view :: MonadReader s m => Getting a s a -> m a
So, you would be able to use this view
with functions, but not in various reader monads. For most people this shouldn't be an issue; if it is for you, use view
from microlens-mtl.
over :: ASetter s t a b -> (a -> b) -> s -> t #
Getting fmap
in a roundabout way:
over
mapped
::Functor
f => (a -> b) -> f a -> f bover
mapped
=fmap
Applying a function to both components of a pair:
over
both
:: (a -> b) -> (a, a) -> (b, b)over
both
= \f t -> (f (fst t), f (snd t))
Using
as a replacement for over
_2
second
:
>>>
over _2 show (10,20)
(10,"20")
type Lens' s a = Lens s s a a #
This is a type alias for monomorphic lenses which don't change the type of the container (or of the value inside).
lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b #
lens
creates a Lens
from a getter and a setter. The resulting lens isn't the most effective one (because of having to traverse the structure twice when modifying), but it shouldn't matter much.
A (partial) lens for list indexing:
ix :: Int ->Lens'
[a] a ix i =lens
(!!
i) -- getter (\s b -> take i s ++ b : drop (i+1) s) -- setter
Usage:
>>> [1..9]^.
ix 3 4 >>> [1..9] & ix 3%~
negate [1,2,3,-4,5,6,7,8,9]
When getting, the setter is completely unused; when setting, the getter is unused. Both are used only when the value is being modified. For instance, here we define a lens for the 1st element of a list, but instead of a legitimate getter we use undefined
. Then we use the resulting lens for setting and it works, which proves that the getter wasn't used:
>>>
[1,2,3] & lens undefined (\s b -> b : tail s) .~ 10
[10,2,3]
class Semigroup a => Monoid a where #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:
x
<>
mempty
= xmempty
<>
x = xx
(<>
(y<>
z) = (x<>
y)<>
zSemigroup
law)mconcat
=foldr
'(<>)'mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
NOTE: Semigroup
is a superclass of Monoid
since base-4.11.0.0.
Identity of mappend
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.mappend
= '(<>)'
Fold a list using the monoid.
For most types, the default definition for mconcat
will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
Instances
Monoid Ordering | Since: base-2.1 |
Monoid () | Since: base-2.1 |
Monoid All | Since: base-2.1 |
Monoid Any | Since: base-2.1 |
Monoid ByteString | |
Defined in Data.ByteString.Lazy.Internal mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
Monoid ByteString | |
Defined in Data.ByteString.Internal mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
Monoid Builder | |
Monoid IntSet | |
Monoid LogStr | |
Monoid PrefsMod | |
Monoid ParseError | |
Defined in Options.Applicative.Types mempty :: ParseError # mappend :: ParseError -> ParseError -> ParseError # mconcat :: [ParseError] -> ParseError # | |
Monoid Completer | |
Monoid ParserHelp | |
Defined in Options.Applicative.Help.Types mempty :: ParserHelp # mappend :: ParserHelp -> ParserHelp -> ParserHelp # mconcat :: [ParserHelp] -> ParserHelp # | |
Monoid [a] | Since: base-2.1 |
Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
Monoid a => Monoid (IO a) | Since: base-4.9.0.0 |
Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0 |
(Ord a, Bounded a) => Monoid (Min a) | Since: base-4.9.0.0 |
(Ord a, Bounded a) => Monoid (Max a) | Since: base-4.9.0.0 |
Monoid m => Monoid (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m # | |
Semigroup a => Monoid (Option a) | Since: base-4.9.0.0 |
Monoid a => Monoid (Identity a) | Since: base-4.9.0.0 |
Monoid (First a) | Since: base-2.1 |
Monoid (Last a) | Since: base-2.1 |
Monoid a => Monoid (Dual a) | Since: base-2.1 |
Monoid (Endo a) | Since: base-2.1 |
Num a => Monoid (Sum a) | Since: base-2.1 |
Num a => Monoid (Product a) | Since: base-2.1 |
Monoid (IntMap a) | |
Monoid (Seq a) | |
Ord a => Monoid (Set a) | |
Monoid (DList a) | |
Monoid (Hints t) | |
Monoid (InfoMod a) | |
Monoid (DefaultProp a) | |
Defined in Options.Applicative.Builder.Internal mempty :: DefaultProp a # mappend :: DefaultProp a -> DefaultProp a -> DefaultProp a # mconcat :: [DefaultProp a] -> DefaultProp a # | |
Monoid (Array a) | |
(Hashable a, Eq a) => Monoid (HashSet a) | |
Monoid (MergeSet a) | |
Monoid b => Monoid (a -> b) | Since: base-2.1 |
Monoid (U1 p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b) => Monoid (a, b) | Since: base-2.1 |
Monoid a => Monoid (ST s a) | Since: base-4.11.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Ord k => Monoid (Map k v) | |
(Stream s, Ord e) => Monoid (ParseError s e) | |
Defined in Text.Megaparsec.Error mempty :: ParseError s e # mappend :: ParseError s e -> ParseError s e -> ParseError s e # mconcat :: [ParseError s e] -> ParseError s e # | |
Monoid (Mod f a) | |
(Eq k, Hashable k) => Monoid (HashMap k v) | |
Applicative f => Monoid (Traversed a f) | |
Monoid (f p) => Monoid (Rec1 f p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: base-2.1 |
Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
(Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0 |
Alternative f => Monoid (Alt f a) | Since: base-4.8.0.0 |
Monoid c => Monoid (K1 i c p) | Since: base-4.12.0.0 |
(Monoid (f p), Monoid (g p)) => Monoid ((f :*: g) p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | Since: base-2.1 |
Monad m => Monoid (ConduitT i o m ()) | |
(Stream s, Monoid a) => Monoid (ParsecT e s m a) | Since: megaparsec-5.3.0 |
Monoid (f p) => Monoid (M1 i c f p) | Since: base-4.12.0.0 |
Monoid (f (g p)) => Monoid ((f :.: g) p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) | Since: base-2.1 |
Monad m => Monoid (Pipe l i o u m ()) | |
data Proxy (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |
A class for types with a default value.
Nothing