File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'dart:io' ;
2+
3+ /// {@template environment_config}
4+ /// A utility class for accessing environment variables.
5+ ///
6+ /// This class provides a centralized way to read configuration values
7+ /// from the environment, ensuring that critical settings like database
8+ /// connection strings are managed outside of the source code.
9+ /// {@endtemplate}
10+ abstract final class EnvironmentConfig {
11+ /// Retrieves the PostgreSQL database connection URI from the environment.
12+ ///
13+ /// The value is read from the `DATABASE_URL` environment variable.
14+ ///
15+ /// Throws a [StateError] if the `DATABASE_URL` environment variable is not
16+ /// set, as the application cannot function without it.
17+ static String get databaseUrl {
18+ final dbUrl = Platform .environment['DATABASE_URL' ];
19+ if (dbUrl == null || dbUrl.isEmpty) {
20+ throw StateError (
21+ 'FATAL: DATABASE_URL environment variable is not set. '
22+ 'The application cannot start without a database connection.' ,
23+ );
24+ }
25+ return dbUrl;
26+ }
27+
28+ /// Retrieves the current environment mode (e.g., 'development', 'production').
29+ ///
30+ /// The value is read from the `ENV` environment variable.
31+ /// Defaults to 'production' if the variable is not set.
32+ static String get environment => Platform .environment['ENV' ] ?? 'production' ;
33+ }
You can’t perform that action at this time.
0 commit comments