util.go

 1package fantasy
 2
 3import "github.com/go-viper/mapstructure/v2"
 4
 5// Opt creates a pointer to the given value.
 6//
 7//go:fix inline
 8func Opt[T any](v T) *T {
 9	return new(v)
10}
11
12// ParseOptions parses the given options map into the provided struct.
13func ParseOptions[T any](options map[string]any, m *T) error {
14	decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
15		TagName: "json",
16		Result:  m,
17	})
18	if err != nil {
19		return err
20	}
21	return decoder.Decode(options)
22}