Skip to content

Macro alternative to fallback to regular env #76

Open

Description

@ShayBox

I use dotenvy! for development to load from .env and env! in production to load from regular env (GitHub Workflows), now I have a feature flag to switch between the two but it's very inconvenient and repetitive.

#[cfg(feature = "production")]
const EXAMPLE_ENV: &str = dotenv!("EXAMPLE_ENV");
#[cfg(not(feature = "production"))]
const EXAMPLE_ENV: &str = env!("EXAMPLE_ENV");

Having a macro that falls back to the regular env would be nice.

Activity

  1. DaXcess commented on Jul 5, 2024

    @DaXcess

    +1

    I was initially under the impression that this was already how dotenvy operated, but unfortunately had to find out the hard way that environment variables in the build pipeline were not accepted by the dotenv! macro, as it throws a compiler error when no .env file is found, even when the environment variable is present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions