pub struct Config {
pub base_url: String,
pub timeout: Duration,
pub retries: u32,
pub log_level: String,
pub deploy_strategy: DeployStrategy,
}Expand description
Configuration for serverless function runtime.
Fields§
§base_url: StringBase URL for remote service calls.
timeout: DurationRequest timeout duration.
retries: u32Number of retries for failed requests.
log_level: StringLog level for the runtime.
deploy_strategy: DeployStrategyDeployment strategy.
Implementations§
Source§impl Config
impl Config
Sourcepub fn builder() -> ConfigBuilder
pub fn builder() -> ConfigBuilder
Creates a new ConfigBuilder for fluent configuration.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Creates a new configuration from environment variables.
§Environment Variables
SERVERLESS_BASE_URL: Base URL for remote calls (default:http://localhost:3000)SERVERLESS_TIMEOUT: Request timeout in milliseconds (default:30000)SERVERLESS_RETRIES: Number of retries (default:3)SERVERLESS_LOG_LEVEL: Log level (default:info)
Examples found in repository?
examples/usage_example.rs (line 60)
58async fn run_client() -> Result<(), ServerlessError> {
59 // Initialize logging
60 let config = serverless_fn::config::Config::from_env();
61 config.init_logging();
62
63 // Initialize telemetry if enabled
64 serverless_fn::telemetry::init_telemetry();
65
66 // Call the serverless function as if it were a regular function
67 let posts = read_posts(3, "my search".to_string()).await?;
68 println!("Retrieved {} posts", posts.len());
69
70 for post in &posts {
71 println!("Post {}: {}", post.id, post.title);
72 }
73
74 // Call another function
75 let new_post =
76 create_post("New Post Title".to_string(), "New Post Content".to_string()).await?;
77
78 println!("Created post: {}", new_post.title);
79
80 Ok(())
81}Sourcepub fn deploy_strategy(&self) -> &DeployStrategy
pub fn deploy_strategy(&self) -> &DeployStrategy
Returns the current deployment strategy.
Sourcepub fn init_logging(&self)
pub fn init_logging(&self)
Initializes logging based on this configuration.
§Panics
Panics if the logging subscriber cannot be initialized.
Examples found in repository?
examples/usage_example.rs (line 61)
58async fn run_client() -> Result<(), ServerlessError> {
59 // Initialize logging
60 let config = serverless_fn::config::Config::from_env();
61 config.init_logging();
62
63 // Initialize telemetry if enabled
64 serverless_fn::telemetry::init_telemetry();
65
66 // Call the serverless function as if it were a regular function
67 let posts = read_posts(3, "my search".to_string()).await?;
68 println!("Retrieved {} posts", posts.len());
69
70 for post in &posts {
71 println!("Post {}: {}", post.id, post.title);
72 }
73
74 // Call another function
75 let new_post =
76 create_post("New Post Title".to_string(), "New Post Content".to_string()).await?;
77
78 println!("Created post: {}", new_post.title);
79
80 Ok(())
81}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
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
Mutably borrows from an owned value. Read more