util.go

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