chore(doc): change basic usage example

This commit is contained in:
Dmitriy Pleshevskiy 2021-04-16 10:35:42 +03:00
parent 257f68eac3
commit 784e0c0d1e
2 changed files with 60 additions and 69 deletions

View file

@ -39,7 +39,7 @@ itconfig = { version = "1.0", features = ["macro"] }
``` ```
## Example usage ## Basic usage
```rust ```rust
use itconfig::config; use itconfig::config;
@ -52,7 +52,8 @@ config! {
#[env_name = "APP_HOST"] #[env_name = "APP_HOST"]
HOST: String => "127.0.0.1", HOST: String => "127.0.0.1",
DATABASE_URL < ( database {
URL < (
"postgres://", "postgres://",
POSTGRES_USERNAME => "user", POSTGRES_USERNAME => "user",
":", ":",
@ -63,39 +64,33 @@ config! {
POSTGRES_DB => "test", POSTGRES_DB => "test",
), ),
APP { pool {
static BASE_URL => "/api", // &'static str by default MAX_SIZE: usize => 15,
},
},
ARTICLE { sentry {
static PER_PAGE: u32 => 15, DSN: Option<&'static str>,
} },
#[cfg(feature = "companies")] feature {
COMPANY { static CORS: bool => false,
#[env_name = "INSTITUTIONS_PER_PAGE"]
static PER_PAGE: u32 => 15,
}
}
FEATURE { static GRAPHQL_PLAYGROUND: bool => false,
NEW_MENU: bool => false, },
COMPANY {
PROFILE: bool => false,
}
}
} }
fn main () { fn main () {
// dotenv().expect("dotenv setup to be successful"); // dotenv().expect("dotenv setup to be successful");
// or // or
env::set_var("FEATURE_NEW_MENU", "t"); env::set_var("FEATURE_CORS", "true");
config::init(); config::init();
assert_eq!(config::HOST(), String::from("127.0.0.1")); assert_eq!(config::HOST(), String::from("127.0.0.1"));
assert_eq!(config::DATABASE_URL(), String::from("postgres://user:pass@localhost:5432/test")); assert_eq!(config::database::URL(), String::from("postgres://user:pass@localhost:5432/test"));
assert_eq!(config::APP::ARTICLE::PER_PAGE(), 15); assert_eq!(config::database::pool::MAX_SIZE(), 15);
assert_eq!(config::FEATURE::NEW_MENU(), true); assert_eq!(config::sentry::DSN(), None);
assert_eq!(config::feature::CORS(), true);
} }
``` ```

View file

@ -32,18 +32,21 @@
//! ``` //! ```
//! //!
//! //!
//! ## Example usage //! ## Basic usage
//! //!
//! ```rust //! ```rust
//! use itconfig::config; //! use itconfig::config;
//! use std::env; //! use std::env;
//! // use dotenv::dotenv; //! //use dotenv::dotenv;
//! //!
//! config! { //! config! {
//! DEBUG: bool => true, //! DEBUG: bool => false,
//!
//! #[env_name = "APP_HOST"]
//! HOST: String => "127.0.0.1", //! HOST: String => "127.0.0.1",
//! //!
//! DATABASE_URL < ( //! database {
//! URL < (
//! "postgres://", //! "postgres://",
//! POSTGRES_USERNAME => "user", //! POSTGRES_USERNAME => "user",
//! ":", //! ":",
@ -54,40 +57,33 @@
//! POSTGRES_DB => "test", //! POSTGRES_DB => "test",
//! ), //! ),
//! //!
//! APP { //! pool {
//! static BASE_URL => "/api", // &'static str by default //! MAX_SIZE: usize => 15,
//! },
//! },
//! //!
//! ARTICLE { //! sentry {
//! static PER_PAGE: u32 => 15, //! DSN: Option<&'static str>,
//! } //! },
//! //!
//! #[cfg(feature = "companies")] //! feature {
//! COMPANY { //! static CORS: bool => false,
//! #[env_name = "INSTITUTIONS_PER_PAGE"]
//! static PER_PAGE: u32 => 15,
//! }
//! }
//! //!
//! FEATURE { //! static GRAPHQL_PLAYGROUND: bool => false,
//! NEW_MENU: bool => false, //! },
//!
//! COMPANY {
//! PROFILE: bool => false,
//! }
//! }
//! } //! }
//! //!
//! fn main () { //! fn main () {
//! // dotenv().expect("dotenv setup to be successful"); //! // dotenv().expect("dotenv setup to be successful");
//! // or //! // or
//! env::set_var("FEATURE_NEW_MENU", "t"); //! env::set_var("FEATURE_CORS", "true");
//! //!
//! config::init(); //! config::init();
//! assert_eq!(config::HOST(), String::from("127.0.0.1")); //! assert_eq!(config::HOST(), String::from("127.0.0.1"));
//! assert_eq!(config::DATABASE_URL(), String::from("postgres://user:pass@localhost:5432/test")); //! assert_eq!(config::database::URL(), String::from("postgres://user:pass@localhost:5432/test"));
//! assert_eq!(config::APP::BASE_URL(), "/api"); //! assert_eq!(config::database::pool::MAX_SIZE(), 15);
//! assert_eq!(config::APP::ARTICLE::PER_PAGE(), 15); //! assert_eq!(config::sentry::DSN(), None);
//! assert_eq!(config::FEATURE::NEW_MENU(), true); //! assert_eq!(config::feature::CORS(), true);
//! } //! }
//! ``` //! ```
//! //!