reflective: Add Reflection{} placeholder and the New() factory

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-09-02 16:18:56 +00:00
parent 7e0b7cfb47
commit a38f0c74e8
+27
View File
@@ -0,0 +1,27 @@
package reflective
import "reflect"
// Reflection provides Marshalling/Unmarshalling oriented view
// of a value
type Reflection struct {
v reflect.Value
}
// New creates a Reflection of the given pointer
func New(v any) (*Reflection, error) {
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Pointer || rv.IsNil() {
err := &InvalidUnmarshalError{
Type: rv.Type(),
}
return nil, err
}
r := &Reflection{
v: rv,
}
return r, nil
}