heetch / heetch/confita

Support for yaml.v3

Open
#95 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
507
Forks
49
PR merge metrics
No merged PRs in 30d

Description

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:
```go
func NewBackend(path string, opts ...BackendOption) *Backend {
...
}
```
and an example option could be:
```go
func WithUnmarshaler(decode func(f io.Reader, to interface{}) error) {
...
}
```
used like this:
```go
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:
```go
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the file.NewBackend entry point and trace how the file backend currently decodes configuration. Check how the existing YAML path is wired and whether its constructor has related optional-backend behavior. Done means yaml.v3 decoding, including custom UnmarshalYAML methods, works without breaking existing yaml.v2 users.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, yaml
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.