1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-16 03:44:26 +00:00
arikawa/internal/rfutil/rfutil.go
diamondburned adce55b02d
discord: Add ContainerComponents.Unmarshal
This feature is similar to the one added a few commits prior.
2022-08-15 14:57:30 -07:00

27 lines
533 B
Go

package rfutil
import (
"errors"
"reflect"
)
func StructValue(v interface{}) (reflect.Value, reflect.Type, error) {
rv := reflect.ValueOf(v)
return StructRValue(rv)
}
func StructRValue(rv reflect.Value) (reflect.Value, reflect.Type, error) {
rt := rv.Type()
if rt.Kind() != reflect.Ptr {
return reflect.Value{}, nil, errors.New("v is not a pointer")
}
rv = rv.Elem()
rt = rt.Elem()
if rt.Kind() != reflect.Struct {
return reflect.Value{}, nil, errors.New("v is not a pointer to a struct")
}
return rv, rt, nil
}