1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Adapter-oriented configuration loading with validation.
//!
//! # Example
//!
//! The end-to-end app example below exercises the `validate`-gated App API
//! (`AppConfig`/`ServiceConfig`/`Validate`), so it only compiles when the
//! default `validate` feature is enabled.
//!
//! use rskit_config::{AppConfig, ConfigLoader, SecretString, ServiceConfig};
//! use rskit_validation::Validate;
//! use serde::Deserialize;
//!
//! #[derive(Debug, Deserialize)]
//! struct MyConfig {
//! #[serde(flatten)]
//! service: ServiceConfig,
//! grpc_port: u16,
//! api_token: SecretString,
//! }
//!
//! impl Validate for MyConfig {
//! fn validate(&self) -> Result<(), validator::ValidationErrors> {
//! self.service.validate()?;
//! if self.grpc_port == 0 {
//! let mut errors = validator::ValidationErrors::new();
//! errors.add("grpc_port", validator::ValidationError::new("range"));
//! return Err(errors);
//! }
//! Ok(())
//! }
//! }
//!
//! impl AppConfig for MyConfig {
//! fn apply_defaults(&mut self) {
//! if self.grpc_port == 0 {
//! self.grpc_port = 50051;
//! }
//! }
//!
//! fn service_config(&self) -> &ServiceConfig {
//! &self.service
//! }
//! }
//!
//! # fn main() -> rskit_errors::AppResult<()> {
//! let cfg: MyConfig = ConfigLoader::app()
//! .with_default("grpc_port", 50051_i64)
//! .with_env_prefix("MYAPP")
//! .load_app()?;
//! assert_eq!(cfg.api_token.to_string(), "***");
//! # Ok(())
//! # }
//! ```
pub use AppConfig;
pub use SecretString;
pub use ;
pub use ;
pub use load_config;
pub use ;
pub use ;
pub use ;