pub struct AppEnvironment {Show 21 fields
pub name: String,
pub version_code: String,
pub build_number: i32,
pub log_sql: bool,
pub server_count: usize,
pub worker_count: usize,
pub socket_count: usize,
pub pg_url: String,
pub redis_url: String,
pub rabbitmq_url: String,
pub rabbitmq_vhost: String,
pub mongodb_url: String,
pub es_url: String,
pub es_api_key: String,
pub server_port: u16,
pub socket_port: u16,
pub prefetch_count: usize,
pub url: String,
pub setup_mode: SetupMode,
pub kind: EnvironmentKind,
pub process_role: ProcessRole,
/* private fields */
}Expand description
Loaded service configuration. Obtain via AppEnvironment::get after provisioning.
Required keys are SERVICE_NAME, SERVICE_VERSION, BUILD_NUMBER,
ENVIRONMENT_KIND, SERVER_PORT, SERVICE_URL, POSTGRESQL_URL,
REDIS_URL, RABBITMQ_URL, and MONGODB_URL; loading fails with
EnvError::MissingKeys when any are absent.
Fields§
§name: StringService name from SERVICE_NAME.
version_code: StringService version from SERVICE_VERSION.
build_number: i32Build number from BUILD_NUMBER.
log_sql: boolWhether SQL statements are logged, from LOG_SQL (defaults to false).
server_count: usizeNumber of HTTP server instances, from SERVER_COUNT (defaults to 1).
worker_count: usizeNumber of worker instances, from WORKER_COUNT (defaults to 0).
socket_count: usizeNumber of socket server instances, from SOCKET_COUNT (defaults to 0).
pg_url: StringPostgres connection URL from POSTGRESQL_URL.
redis_url: StringRedis connection URL from REDIS_URL.
rabbitmq_url: StringRabbitMQ connection URL from RABBITMQ_URL.
rabbitmq_vhost: StringRabbitMQ virtual host from RABBITMQ_VHOST (defaults to "/").
mongodb_url: StringMongoDB connection URL from MONGODB_URL.
es_url: StringElasticsearch URL from ELASTICSEARCH_URL (defaults to "<none>").
es_api_key: StringElasticsearch API key from ELASTICSEARCH_API_KEY (defaults to "<none>").
server_port: u16HTTP listen port from SERVER_PORT.
socket_port: u16Socket listen port from SOCKET_PORT (defaults to 8081).
prefetch_count: usizeQueue prefetch count from PREFETCH_COUNT (defaults to 1).
url: StringPublic service URL from SERVICE_URL.
setup_mode: SetupModeSetup selector from SETUP_MODE (defaults to production).
kind: EnvironmentKindDeployment environment selector from ENVIRONMENT_KIND.
process_role: ProcessRoleProcess role from PROCESS_ROLE (defaults to worker).
Implementations§
Source§impl AppEnvironment
impl AppEnvironment
Sourcepub fn with_env_file(path: Option<&str>) -> Result<(), EnvError>
pub fn with_env_file(path: Option<&str>) -> Result<(), EnvError>
Provisions the singleton from the given dotenv file, or from .env plus the
process environment when path is None. Idempotent: no-ops when already provisioned.
Returns EnvError::MissingKeys when a required key is absent, or
EnvError::InvalidValue when a value fails to parse.
Sourcepub fn get() -> &'static Self
pub fn get() -> &'static Self
Returns the provisioned environment.
Panics when AppEnvironment::with_env_file has not run yet.
Sourcepub fn try_get() -> Option<&'static Self>
pub fn try_get() -> Option<&'static Self>
Returns the provisioned environment, or None when not yet provisioned.
Sourcepub fn is_production(&self) -> bool
pub fn is_production(&self) -> bool
Reports whether the environment kind is production.
Sourcepub fn should_log_sql(&self) -> bool
pub fn should_log_sql(&self) -> bool
Reports whether SQL statement logging is enabled (LOG_SQL).
Sourcepub fn get_value(&self, key: &str) -> Option<String>
pub fn get_value(&self, key: &str) -> Option<String>
Looks up key in the loaded map, falling back to the process environment. Returns None when absent in both.
Sourcepub fn get_required(&self, key: &str) -> Result<String, EnvError>
pub fn get_required(&self, key: &str) -> Result<String, EnvError>
Looks up key as in AppEnvironment::get_value. Returns EnvError::MissingKeys when absent in both.
Trait Implementations§
Source§impl Clone for AppEnvironment
impl Clone for AppEnvironment
Auto Trait Implementations§
impl Freeze for AppEnvironment
impl RefUnwindSafe for AppEnvironment
impl Send for AppEnvironment
impl Sync for AppEnvironment
impl Unpin for AppEnvironment
impl UnsafeUnpin for AppEnvironment
impl UnwindSafe for AppEnvironment
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more