Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this will not work for private attributes #68

Closed
lukluk opened this issue Feb 15, 2021 · 5 comments
Closed

this will not work for private attributes #68

lukluk opened this issue Feb 15, 2021 · 5 comments

Comments

@lukluk
Copy link

lukluk commented Feb 15, 2021

No description provided.

@kz
Copy link

kz commented Feb 25, 2021

I ran into this problem too, and I notice Kelsey Hightower's envconfig package also does not check whether the field you are attempting to set is unexported. Assuming there is no other case where a developer would set the env tag on an unexported field other than intending for that field to be exported, should unexported fields with env tags throw errors? (https://groups.google.com/g/golang-nuts/c/i50jwcgHAcs)

@ilyakaznacheev
Copy link
Owner

This is a standard and expected behavior of Golang - library cannot read unexported fields from another package.

The expected behavior it that such fields will be ignored.

@saddit
Copy link
Contributor

saddit commented Oct 16, 2022

@ilyakaznacheev

panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

goroutine 1 [running]:
reflect.valueInterface({0x95f8a0?, 0xc00055c248?, 0xabea8f?}, 0xa?)
        E:/software/dev_core/go1.18.1/src/reflect/value.go:1441 +0xd8
reflect.Value.Interface(...)
        E:/software/dev_core/go1.18.1/src/reflect/value.go:1430
github.com/ilyakaznacheev/cleanenv.readStructMetadata({0x9c7900?, 0xc00055c1c0?})

        E:/text/code-project/GolangProject/pkg/mod/github.com/ilyakaznacheev/cleanenv@v1.3.0/cleanenv.go:274 +0x771
github.com/ilyakaznacheev/cleanenv.readEnvVars({0x9c7900, 0xc00055c1c0}, 0x0)

        E:/text/code-project/GolangProject/pkg/mod/github.com/ilyakaznacheev/cleanenv@v1.3.0/cleanenv.go:333 +0x45
github.com/ilyakaznacheev/cleanenv.ReadConfig({0xace493?, 0xc00041f9a8?}, {0x9c7900, 0xc00055c1c0})


        E:/text/code-project/GolangProject/pkg/mod/github.com/ilyakaznacheev/cleanenv@v1.3.0/cleanenv.go:95 +0x48

It doesn't skip unexport field

@ilyakaznacheev
Copy link
Owner

@838239178 can you provide a code example, please?

@ilyakaznacheev
Copy link
Owner

Better create a new issue with an example and detailed error and environment description. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants