Browse Source

reflection: add initial New() validating type and triggering a scan

Signed-off-by: Alejandro Mery <amery@jpi.io>
dev-amery-reflect
Alejandro Mery 1 year ago
parent
commit
dd252fafae
  1. 35
      reflection/reflection.go
  2. 5
      reflection/scan.go

35
reflection/reflection.go

@ -1,2 +1,37 @@
// Package reflection helps Marshalling/Unmarshalling data to structs
package reflection
import (
"reflect"
)
// Reflection provides Marshalling/Unmarshalling oriented view
// of a value
type Reflection struct {
v reflect.Value
}
// Value returns the object it reflects
func (r *Reflection) Value() any {
return r.v.Interface()
}
// 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,
}
if err := r.scan(); err != nil {
return nil, err
}
return r, nil
}

5
reflection/scan.go

@ -0,0 +1,5 @@
package reflection
func (*Reflection) scan() error {
return nil
}
Loading…
Cancel
Save