Safe Haskell | None |
---|
Synopsis
- env :: forall result monad. (MonadIO monad, EnvVarReader result) => ByteString -> monad result
- envOrDefault :: (MonadIO monad, EnvVarReader result) => ByteString -> result -> monad result
- envOrNothing :: (MonadIO monad, EnvVarReader result) => ByteString -> monad (Maybe result)
- hasEnvVar :: MonadIO monad => ByteString -> monad Bool
- class EnvVarReader valueType where
- envStringToValue :: ByteString -> Either Text valueType
Documentation
env :: forall result monad. (MonadIO monad, EnvVarReader result) => ByteString -> monad result Source #
Returns a env variable. The raw string value is parsed before returning it. So the return value type depends on what you expect (e.g. can be Text, Int some custom type).
When the parameter is missing or cannot be parsed, an error is raised and
the app startup is aborted. Use envOrDefault
when you want to get a
default value instead of an error, or paramOrNothing
to get Nothing
when the env variable is missing.
You can define a custom env variable parser by defining a EnvVarReader
instance.
Example: Accessing a env var PORT.
Let's say an env var PORT is set to 1337
export PORT=1337
We can read PORT
like this:
port <- env @Int "PORT"
Example: Missing env vars
Let's say the PORT
env var is not defined. In that case we'll get an
error when trying to access it:
>>>
port <- env @Int "PORT"
"Env var 'PORT' not set, but it's required for the app to run"
envOrDefault :: (MonadIO monad, EnvVarReader result) => ByteString -> result -> monad result Source #
envOrNothing :: (MonadIO monad, EnvVarReader result) => ByteString -> monad (Maybe result) Source #
class EnvVarReader valueType where Source #
envStringToValue :: ByteString -> Either Text valueType Source #
Instances
EnvVarReader ByteString Source # | |
Defined in IHP.EnvVar | |
EnvVarReader Environment Source # | |
Defined in IHP.EnvVar | |
EnvVarReader AppPort Source # | |
Defined in IHP.FrameworkConfig | |
EnvVarReader SMTPEncryption Source # | Allow reading the env var of an SMTP encryption method. |
Defined in IHP.EnvVar | |
EnvVarReader PortNumber Source # | Allow reading the env var of an SMTP port number. |
Defined in IHP.EnvVar envStringToValue :: ByteString -> Either Text PortNumber Source # | |
EnvVarReader Text Source # | |
Defined in IHP.EnvVar envStringToValue :: ByteString -> Either Text Text Source # | |
EnvVarReader IPAddrSource Source # | |
Defined in IHP.FrameworkConfig envStringToValue :: ByteString -> Either Text IPAddrSource Source # | |
EnvVarReader String Source # | |
Defined in IHP.EnvVar | |
EnvVarReader Bool Source # | |
Defined in IHP.EnvVar envStringToValue :: ByteString -> Either Text Bool Source # | |
EnvVarReader Int Source # | |
Defined in IHP.EnvVar envStringToValue :: ByteString -> Either Text Int Source # |