Skip to content

Optional prefix handling #218

@dortizrv

Description

@dortizrv

Hi, I was checking and when starting the process:
err = envconfig.Process("MYAPP", &config)

In this case, I don't want to use prefixes, which should normally be allowed, but since I didn't specify it, I'd still have to define my environment variables as follows:

go struct

type config struct {
Host string
User string
Password string
}

env file

_HOST=""
_USER=""
_PASSWORD=""

This wouldn't be very suitable if I wanted to freely manage my environment variables. I found a one-line solution to handle this:

/home//go/pkg/mod/github.com/kelseyhightower/[email protected]/envconfig.go

:118
info.Key = strings.Join(name, "_")

Replace with:
if prefix != "" {
info.Key = strings.Join(name, "_")
}

env file

HOST=""
USER=""
PASSWORD=""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions