env
On this page:
- spider.env: Environment variables, with
.envloaded:spider.env.getOr("NAME", "default").
spider.env
Environment variables, with the project's .env files loaded on first use (spider.env). A variable the process already has (set by the shell, the container, a CI job) always wins: the files only fill in what is missing. Among the files, .env.local wins over .env.<SPIDER_ENV> (development when SPIDER_ENV is not set), which wins over .env.
A file has one NAME=value per line. Blank lines and lines that start with # are skipped, spaces around the name and the value are dropped, and one pair of quotes around the value ("..." or '...') is removed. There is no export prefix, no escape and no $NAME expansion, and a # after a value is part of the value. A file over 64 KiB is not loaded, and a warning says so.
spider.env.get
pub fn get(key: []const u8) ?[]const u8
The value of the variable key, or null when it is not set. The first call loads the .env files of the working directory (see the top of this file).
The result is the process's own copy of the value, valid while the process runs: nothing is allocated, so it can be read on every request.
if (spider.env.get("JWT_SECRET")) |secret| { ... }
spider.env.getOr
pub fn getOr(key: []const u8, default: []const u8) []const u8
The value of the variable key, or default (returned as given, not copied) when it is not set. A variable set to an empty string is set.
const realm = spider.env.getOr("KEYCLOAK_REALM", "");
spider.env.getInt
pub fn getInt(comptime T: type, key: []const u8, default: T) T
The variable key as a base-10 integer of type T. Gives default when the variable is not set, is not a number or does not fit in T.
spider.env.getBool
pub fn getBool(key: []const u8, default: bool) bool
The variable key as a boolean: "true", "1", "yes" and "on" are true; "false", "0", "no" and "off" are false, in any letter case. Gives default when the variable is not set or holds anything else.