IHP Api Reference
Safe HaskellSafe-Inferred

IHP.EnvVar

Synopsis

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 #

hasEnvVar :: MonadIO monad => ByteString -> monad Bool Source #

class EnvVarReader valueType where Source #

Instances

Instances details
EnvVarReader ByteString Source # 
Instance details

Defined in IHP.EnvVar

EnvVarReader Environment Source # 
Instance details

Defined in IHP.EnvVar

EnvVarReader AppPort Source # 
Instance details

Defined in IHP.FrameworkConfig

EnvVarReader Text Source # 
Instance details

Defined in IHP.EnvVar

EnvVarReader IPAddrSource Source # 
Instance details

Defined in IHP.FrameworkConfig

Methods

envStringToValue :: ByteString -> Either Text IPAddrSource Source #

EnvVarReader String Source # 
Instance details

Defined in IHP.EnvVar

EnvVarReader Bool Source # 
Instance details

Defined in IHP.EnvVar

EnvVarReader Int Source # 
Instance details

Defined in IHP.EnvVar