Skip to content

Adding mapping prefix (and possibly suffix too?!) #2

@xarunoba

Description

@xarunoba

We can add another declaration called prefix within the env declaration that is used to group prefixed env vars. For example:

const Config = struct {
    name: []const u8, // Maps to "APP_NAME" env var
    port: u32, // Maps to "APP_PORT" env var
    debug: bool = false, // Maps to "APP_DEBUG" env var
    timeout: ?f32 = null, // Maps to "APP_TIMEOUT" env var

    const env = .{
        .name = "NAME",
        .port = "PORT",
        .debug = "DEBUG",
        .timeout = "TIMEOUT",

        const prefix = "APP_"
        // const suffix = "_TEST"
    };
};

const config = try env_struct.load(Config, allocator);

The initial plan is to apply this prefix recursively for nested structs. I'll probably also include support for suffix since, why not?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions