Skip to content

The env attribute cannot be specified as an attribute of a struct #1545

@PrimaryCY

Description

@PrimaryCY

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I am not looking for support or already pursued the available support channels without success.
  • I have checked the troubleshooting guide for my problem, without success.

Viper Version

1.15.0

Go Version

1.17.8

Config Source

Environment variables

Format

Other (specify below)

Repl.it link

No response

Code reproducing the issue

func main(){
        type C struct {
		HOME string `mapstructure:"HOME"`
	}

	c := C{}

	viper.AutomaticEnv()
	err := viper.Unmarshal(&c)
	if err != nil {
		panic(err)
	}
	fmt.Println(c.HOME)
	fmt.Println(viper.Get("HOME"))

}

Expected Behavior

I want to get the value of home from the structure
output:
/Users/cy
/Users/cy

Actual Behavior

output:

/Users/cy

Steps To Reproduce

computer:
macOS Catalina version: 10.15.7(19h15)
MacBook Pro (15-inch, 2018)

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions