Util types and functions to quickly and easy set up an HTTP server from environment variables (although you can omit env variables).
Once you have the Rust objects with all the basic information you need for your server,
like the database connection (DATABASE_URL
), the deployment environment (APP_ENV
)
or the port where to start the app (PORT
), you can use the struct objects
to use those values to start up your Actix server, Rocket server, or whatever
server your app use.
Check the 📖 docs at https://docs.rs/server-env-config/.
```rust use std::env; use serverenvconfig::Config; use serverenvconfig::env::Environment;
// Configurations should be actually set by the OS environment env::setvar("APPENV", "production"); // if not set, "local" is the default env::setvar("APPURI", "api/v1"); env::setvar("PORT", "8080"); env::setvar("DATABASE_URL", "postgresql://user:pass@localhost/db");
let result = Config::init(9999); // 9999 will be used if "PORT" is not set assert!(result.isok()); let config = result.unwrap(); asserteq!(config.env, Environment::Production); asserteq!(config.server.port, 8080); asserteq!(config.server.url, "http://127.0.0.1:8080/api/v1/"); // calculated field asserteq!(config.db.databaseurl, "postgresql://user:pass@localhost/db"); // Some settings have default values if env variables are not set asserteq!(config.db.minconnections, 1); asserteq!(config.db.maxconnections, 10); ```
Project Home: https://github.com/mrsarm/rust-actix-contrib-rest.
This project is licensed under either of the following licenses, at your option: