spf13 / viper

Go configuration with fangs
MIT License
26.32k stars 2.01k forks source link

Deserialization exceptions #1745

Closed bystart closed 5 months ago

bystart commented 5 months ago

Preflight Checklist

Viper Version

1.16

Go Version

1.21.1

Config Source

Defaults

Format

No response

Repl.it link

No response

Code reproducing the issue

type ApplicationConfig struct {
    appName string `yaml:"appName"`
    Version string `yaml:"version"`
}
type DBConfig struct {
    Host     string `yaml:"host"`
    Port     int    `yaml:"port"`
    Username string `yaml:"username"`
    Password string `yaml:"password"`
}

type RedisConfig struct {
    Host string `yaml:"host"`
    Port int    `yaml:"port"`
}

type AppConfig struct {
    ApplicationConfig ApplicationConfig `yaml:"application"`
    DB                DBConfig          `yaml:"db"`
    Redis             RedisConfig       `yaml:"redis"`
}
--------------

Expected Behavior

The ApplicationConfig field property cannot be serialized

Actual Behavior

The ApplicationConfig field property cannot be serialized

Steps To Reproduce

No response

Additional Information

image

github-actions[bot] commented 5 months ago

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

bystart commented 5 months ago

type ApplicationConfig struct { AppName string yaml:"appName" Version string yaml:"version" } type DBConfig struct { Host string yaml:"host" Port int yaml:"port" Username string yaml:"username" Password string yaml:"password" }

type RedisConfig struct { Host string yaml:"host" Port int yaml:"port" }

type AppConfig struct { ApplicationConfig ApplicationConfig yaml:"application" DB DBConfig yaml:"db" Redis RedisConfig yaml:"redis" }

sagikazarmark commented 5 months ago

No idea how your other values get set, but my guess is they come from some defaults.

https://github.com/spf13/viper/blob/master/TROUBLESHOOTING.md#unmarshaling-doesnt-work

https://github.com/spf13/viper#unmarshaling