diff options
Diffstat (limited to 'danmaku/dmmsg/util.go')
-rw-r--r-- | danmaku/dmmsg/util.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/danmaku/dmmsg/util.go b/danmaku/dmmsg/util.go new file mode 100644 index 0000000..9d41ab9 --- /dev/null +++ b/danmaku/dmmsg/util.go @@ -0,0 +1,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 +} |