Safe Haskell | None |
---|---|
Language | Haskell2010 |
Include the value of an environment variable in the binary at compile time.
Rationale
Users might want to embed secrets (e.g. API keys, database connection strings) inside production artifacts without checking these into the repository.
Examples
NB : all library functions require the TemplateHaskell
language extension.
Include a single variable
In this case, the name of the user's current shell) :
import IncludeEnv.TH (includeEnv)
$(includeEnv
"SHELL" "shl")
shl :: String
main :: IO ()
main = putStrLn $ unwords ["your current shell :", shl]
Include a group of variables as a name-value map
import IncludeEnv.TH (includeEnvMap)
env = $(includeEnvMap
["TERM", "USER"])
>>> env fromList [("TERM","dumb"),("USER","marco")]
Synopsis
- includeEnv :: String -> String -> Q [Dec]
- includeEnvLenient :: String -> String -> Q [Dec]
- includeEnvMaybe :: String -> Q Exp
- includeEnvMap :: Foldable t => t String -> Q Exp
Documentation
Like includeEnv
but only prints a warning if the environment variable cannot be found.
NB : If the lookup fails, the declared value will contain an _empty string_ .
Like includeEnv
but produces a 'Maybe String'
Use case : The program needs to be compiled against two different environments that may have different sets of environment variables. includeEnvMaybe
lets you account for the results of multiple such lookups at runtime.
Since: 0.4.0.0