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

Support for yaml.v3 #95

Open
kszafran opened this issue Oct 10, 2024 · 0 comments
Open

Support for yaml.v3 #95

kszafran opened this issue Oct 10, 2024 · 0 comments

Comments

@kszafran
Copy link

In my application I'm using yaml.v3 instead of yaml.v2, which confita uses. This makes it problematic, since confita cannot read my types that have custom UnmarshalYAML methods (the signature differs between yaml.v2 and yaml.v3).

I believe support for yaml.v3 could be added in a backwards compatible way, e.g. by passing opts to file.NewBackend(...). For example:

func NewBackend(path string, opts ...BackendOption) *Backend {
	...
}

and an example option could be:

func WithUnmarshaler(decode func(f io.Reader, to interface{}) error) {
	...
}

used like this:

import "gopkg.in/yaml.v3"

...

file.NewBackend("myfile.yaml", file.WithUnmarshaler(func(f io.Reader, to interface{}) error {
	return yaml.NewDecoder(f).Decode(to)
}))

As a side effect, this would also allow supporting any file format, not just the built-in yaml, json, and toml.

Alternatively, if introducing functional options is undesirable, we could instead add new functions like:

type Umarshaler func(f io.Reader, to interface{}) error 

func NewCustomBackend(path string, unmarshaler Unmarshaler) *Backend { ... }
func NewOptionalCustomBackend(path string, unmarshaler Unmarshaler) *Backend { ... }

What do you think? It should be a simple change and I could contribute a PR if this is something you'd be interested in.

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

1 participant