Skip to content

Didn't skip unexported field #105

@saddit

Description

@saddit

@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 unexported field

Originally posted by @838239178 in #68 (comment)

Example

package main

import (
	"github.com/ilyakaznacheev/cleanenv"
)

type Children struct {
	name string `yaml:"name" env:"name"`
}

type Config struct {
	private Children `yaml:"private" env-prefix:"private"`
	Public string `yaml:"public" env:"public"`
}

func main()  {
	var conf Config
	if err := cleanenv.ReadConfig("config.yml", &conf); err != nil {
		panic(err)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions