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