defaults
defaults copied to clipboard
Set does not report errors
Given the following code
package main
import (
"fmt"
"github.com/creasty/defaults"
)
type Kitten struct {
MaxHP int `default:"powerfull"`
}
func main() {
var k Kitten
if err := defaults.Set(&k); err != nil {
panic(fmt.Sprintf("Bad Kitty %v", err))
} else {
fmt.Printf("Good Kitty %#v\n", k)
}
}
It prints "Good Kitty main.Kitten{MaxHP:0}" , I think Set should return an error in this case
Playground link https://go.dev/play/p/KUi5L1hP-IF
Just ran into this myself. At the very least there should be a configuration option to specify whether errors should be thrown or just let it set the zero value.