summaryrefslogtreecommitdiff
path: root/danmaku/dmmsg/util.go
blob: 9d41ab96e4962a8ce5df0ceed479e58d528f54a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package dmmsg

import (
	"fmt"
	"reflect"
)

func castValue[T any](obj interface{}) (thing T, err error) {
	casted, ok := (obj).(T)
	if !ok {
		err = fmt.Errorf("%s: required value is not of type \"%v\": %v",
			kInvalidDanmakuJson, reflect.TypeOf(thing).String(), obj)
		return
	}
	thing = casted
	return
}