magiconair / properties

Java properties scanner for Go
BSD 2-Clause "Simplified" License
323 stars 77 forks source link

Add an ability to do not fail Decode function if no 'default' value specified in the 'properties' tag #33

Open alxeg opened 6 years ago

alxeg commented 6 years ago

Currently the Decode function returns an error if the tag does not contain 'default' and the key does not exist in the properties file.

Sometimes it's preferable to do not fail in this case but use the original field value of the structure passed to the Decode function, e.g by passing some specific key ('predefined') to the properties tag:

type Config struct {
    Field string `properties:"somefield,predefined"`
}

conf := &Config{
    Field: "Default value"
}

p := properties.MustLoadFiles([]string{
    "config.properties",
}, properties.UTF8, true)

err := p.Decode(conf)

if err == nil {
    fmt.Println(conf.Field)
}