value.go 746 B

123456789101112131415161718192021222324252627282930313233
  1. package data
  2. import "reflect"
  3. // Value is a writable value.
  4. type Value interface {
  5. // Kind returns value's Kind.
  6. Kind() reflect.Kind
  7. // Len returns value's length.
  8. // It panics if value's Kind is not Array, Chan, Map, Slice, or String.
  9. Len() int
  10. // Index returns value's i'th element.
  11. // It panics if value's Kind is not Array, Slice, or String or i is out of range.
  12. Index(i int) Value
  13. // Interface returns value's current value as an interface{}.
  14. Interface() interface{}
  15. }
  16. // value is a wrapper that wraps reflect.Value to comply with Value interface.
  17. type value struct {
  18. reflect.Value
  19. }
  20. func newValue(v reflect.Value) Value {
  21. return value{Value: v}
  22. }
  23. func (v value) Index(i int) Value {
  24. return newValue(v.Value.Index(i))
  25. }