-
Notifications
You must be signed in to change notification settings - Fork 158
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
Disable tag support #5
Comments
koanf uses the mapstructure package to do the unmarshalling. Looks like mapstructure implicitly behaves the way you described. That is, if there's no tag on a struct field, it unmarshals it any way. I'll investigate more and document this behaviour. package main
import (
"fmt"
"log"
"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/json"
"github.com/knadh/koanf/providers/file"
)
func main() {
var k = koanf.New(".")
// struct with no 'koanf' tags.
type test struct {
Type string
}
// Load JSON config.
if err := k.Load(file.Provider("mock/mock.json"), json.Parser()); err != nil {
log.Fatalf("error loading config: %v", err)
}
var out test
k.Unmarshal("", &out)
fmt.Println(out)
} |
Oh, okay. It's kind of misleading 😕 |
Added a wiki entry to document this: https://github.com/knadh/koanf/wiki#mapstructure |
Hello,
Is it possible to disable tag support with
UnmarshalWithConf
so we could unmarshal a konf instance to a struct without having to provides tags?Reference: https://github.com/knadh/koanf/blob/master/koanf.go#L199
Like adding a new field called
DisableTag
as a boolean (in order to avoid compatibility break).Let me know what you think.
Thank you in advance.
The text was updated successfully, but these errors were encountered: