From 00595609af53514ffd39d9aeab0d33e6d84cbdb5 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 7 Sep 2022 12:45:46 +0800 Subject: More comprehensive danmaku message handling. --- danmaku/dmmsg/util.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 danmaku/dmmsg/util.go (limited to 'danmaku/dmmsg/util.go') 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 +} -- cgit v1.2.3