Skip to content

Commit 4763493

Browse files
committed
Make a module to eliminate typos in repeating the environment variable names
1 parent 4fa0b11 commit 4763493

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

ui/src/env.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub use std::env::*;
2+
3+
pub const PLAYGROUND_GITHUB_TOKEN: &str = "PLAYGROUND_GITHUB_TOKEN";

ui/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![deny(rust_2018_idioms)]
22

3+
use crate::env::PLAYGROUND_GITHUB_TOKEN;
34
use serde::{Deserialize, Serialize};
45
use snafu::prelude::*;
56
use std::{
67
convert::TryFrom,
7-
env,
88
net::SocketAddr,
99
path::{Path, PathBuf},
1010
sync::Arc,
@@ -14,6 +14,7 @@ const DEFAULT_ADDRESS: &str = "127.0.0.1";
1414
const DEFAULT_PORT: u16 = 5000;
1515

1616
mod asm_cleanup;
17+
mod env;
1718
mod gist;
1819
mod metrics;
1920
mod sandbox;
@@ -54,7 +55,6 @@ impl Config {
5455
.and_then(|p| p.parse().ok())
5556
.unwrap_or(DEFAULT_PORT);
5657

57-
const PLAYGROUND_GITHUB_TOKEN: &str = "PLAYGROUND_GITHUB_TOKEN";
5858
let gh_token = env::var(PLAYGROUND_GITHUB_TOKEN).ok();
5959
if gh_token.is_none() {
6060
log::warn!("Environment variable {} is not set, so reading and writing GitHub gists will not work", PLAYGROUND_GITHUB_TOKEN);
@@ -149,7 +149,7 @@ pub enum Error {
149149
GistCreation { source: octocrab::Error },
150150
#[snafu(display("Gist loading failed: {}", source))]
151151
GistLoading { source: octocrab::Error },
152-
#[snafu(display("PLAYGROUND_GITHUB_TOKEN not set up for reading/writing gists"))]
152+
#[snafu(display("{PLAYGROUND_GITHUB_TOKEN} not set up for reading/writing gists"))]
153153
NoGithubToken,
154154
#[snafu(display("Unable to serialize response: {}", source))]
155155
Serialization { source: serde_json::Error },

0 commit comments

Comments
 (0)