Alejandro Mery
1 year ago
1 changed files with 27 additions and 0 deletions
@ -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 |
||||
} |
Loading…
Reference in new issue