diff options
author | Keuin <[email protected]> | 2022-09-07 12:45:46 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-09-07 12:47:25 +0800 |
commit | 00595609af53514ffd39d9aeab0d33e6d84cbdb5 (patch) | |
tree | acb89f406dade1662090facd740a7ccc5d90433c /danmaku/dmmsg/util.go | |
parent | c78edaa0ffa28bb360663f172e98540b7978e9b2 (diff) |
More comprehensive danmaku message handling.
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 +} |