Skip to content

Instantly share code, notes, and snippets.

@UltiRequiem
Created February 7, 2022 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UltiRequiem/9a352f54f6df8084d4720792cb4f54a3 to your computer and use it in GitHub Desktop.
Save UltiRequiem/9a352f54f6df8084d4720792cb4f54a3 to your computer and use it in GitHub Desktop.
get env vars rust
use std::env;
const DEFAULT_PORT: u16 = 3000;
const DEFAULT_SERVER_MODE: &str = "DEV";
fn main() {
let server_port = env::var("SERVER_PORT").unwrap_or(DEFAULT_PORT.to_string());
let server_mode = env::var("SERVER_MODE").unwrap_or(DEFAULT_SERVER_MODE.to_string());
println!(
"Starting server in {} mode on port {}.",
server_mode, server_port
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment