Expand description
The configuration keys Rainier itself reads — a typed index of the tree.
Some frameworks answer “what can I configure?” with a shipped file to read through. Rainier’s answer is this module: every key the framework writes or reads, with the type stored at it.
use rainier_framework::config::Config;
use rainier_framework::keys;
let config = Config::new();
config.set(keys::APP_NAME, "My App".to_string()).unwrap();
assert_eq!(config.get(keys::APP_NAME).as_deref(), Some("My App"));Using them is optional — every Config method still takes a &str — but
it is what turns two classes of silent mistake into compile errors:
ⓘ
// The port is a u16, so this does not compile.
config.set(keys::SERVER_PORT, "8000").unwrap();ⓘ
// Neither does a driver spelled as a string.
config.set(keys::CACHE_DRIVER, "redis").unwrap();§Reading a driver
The driver keys hold settings — closed sets with
their own parser. Read them with Config::setting, which distinguishes
unset (use the default) from set to nonsense (fail, and list what was
expected):
use rainier_framework::cache::CacheDriver;
use rainier_framework::config::Config;
use rainier_framework::keys;
let config = Config::new();
config.set(keys::CACHE_DRIVER, CacheDriver::Redis).unwrap();
match config.setting(keys::CACHE_DRIVER).unwrap() {
CacheDriver::Memory => { /* … */ }
CacheDriver::Redis | CacheDriver::RedisCluster => { /* … */ }
CacheDriver::Memcached => { /* … */ }
CacheDriver::DynamoDb => { /* … */ }
// A `_` arm is worth having: a driver added to the framework is a new
// variant, and a new variant stops an exhaustive match compiling.
other => panic!("this application does not build a {other}"),
}§Adding your own
An application declares its keys the same way, next to the section that writes them:
use rainier_framework::config::config_keys;
config_keys! {
/// How many posts a listing shows.
pub POSTS_PER_PAGE: u64 = "posts.per_page";
}Constants§
- APP_
BASE_ PATH - The directory the application was started from. Set by the framework; there is no environment variable for it.
- APP_
CIPHER - Which encryption envelope this application writes —
nativeorphp. - APP_
DEBUG - Whether a failure may show its internals to the client.
- APP_ENV
- Which deployment this is.
- APP_
NAME - The application’s display name, in page titles and mail.
- APP_URL
- The application’s canonical base URL, used to generate absolute links.
- CACHE_
DRIVER - Which cache store to build.
- CACHE_
MEMCACHED_ URL host:portof the Memcached server.- CACHE_
PREFIX - Prepended to every cache key, so two applications can share a server.
- CACHE_
REDIS_ URL - The Redis DSN, or a comma-separated seed list for a cluster.
- DATABASE_
URL - The database DSN —
sqlite::memory:,mysql://…,postgres://…. - KAFKA_
BROADCAST_ TOPIC - The topic broadcasts are published to.
- KAFKA_
BROKERS - The bootstrap brokers, comma-separated —
kafka-1:9092,kafka-2:9092. - KAFKA_
GROUP - Which set of cursors this deployment shares.
- KAFKA_
PASSWORD - The SASL password.
- KAFKA_
SASL_ MECHANISM - Which SASL mechanism the username and password are for.
- KAFKA_
TLS - Whether to connect over TLS. Needs the
kafka-tlsfeature. - KAFKA_
TOPIC_ PREFIX - Prefixes every topic this application produces to or reads from.
- KAFKA_
USERNAME - The SASL username, if the cluster wants one.
- LOG_
FORMAT - The shape of a log line —
auto,pretty,compact,json. - MAIL_
DRIVER - Where mail goes.
- MAIL_
FROM_ ADDRESS - The default
Fromaddress. - MAIL_
FROM_ NAME - The default
Fromdisplay name. - METRICS_
ENABLED - Whether to record Prometheus metrics.
- METRICS_
PATH - The path the scrape endpoint is served at.
- OPENAPI_
ENABLED - Whether to serve the OpenAPI document.
- OPENAPI_
PATH - The path the document is served at.
- OPENAPI_
SERVER - The base URL clients should use, if the document should name one.
- OPENAPI_
TITLE - The
info.titleof the document. - OPENAPI_
VERSION - The
info.versionof the document — your API’s version, not the framework’s. - QUEUE_
DEFAULT - The queue a job goes on when it does not name one.
- QUEUE_
DRIVER - Where queued jobs wait.
- SERVER_
COMPRESSION - Whether to gzip text responses on the way out.
- SERVER_
HOST - The interface the HTTP server binds to.
- SERVER_
MAX_ BODY_ BYTES - The largest request body that will be buffered, in bytes.
- SERVER_
PORT - The port the HTTP server binds to.
- SERVER_
REQUEST_ TIMEOUT_ SECS - How long a handler may take before the request is cancelled and
answered
408, in seconds.0turns it off. - SESSION_
COOKIE - The name of the session cookie.
- SESSION_
DRIVER - Where session state lives.
- SESSION_
LIFETIME - How long a session survives without a request, in seconds.
- SESSION_
SECURE - Whether the session cookie is
Secure. Must be true over HTTPS. - TELEMETRY_
ENABLED - Whether to join and propagate W3C trace context.
- TELEMETRY_
ENDPOINT - The OTLP collector’s gRPC endpoint —
http://localhost:4317. - TELEMETRY_
SAMPLE_ RATIO - What fraction of traces this service starts to record,
0.0to1.0. - TELEMETRY_
SERVICE_ NAME - What this service calls itself in a trace.