Skip to content

Allow reading from fs.FS #135

@Aquarthur

Description

@Aquarthur

Provide an interface for the user to pass in an fs.FS alongside a filename.

This will add some flexibility about how the file is loaded, and makes it easier for users to write tests to verify configs via testing/fstest.

Something like:

type ConfigDatabase struct {
	Port     string `yaml:"port" env:"PORT" env-default:"5432"`
	Host     string `yaml:"host" env:"HOST" env-default:"localhost"`
	Name     string `yaml:"name" env:"NAME" env-default:"postgres"`
	User     string `yaml:"user" env:"USER" env-default:"user"`
	Password string `yaml:"password" env:"PASSWORD"`
}

var cfg ConfigDatabase

fsys := os.DirFS("/example/config/folder")
err := cleanenv.ReadConfigFS(fsys, "config.yml", &cfg)
if err != nil {
	...
}

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