func resolvePointer(obj interface{}) (interface{}, bool) {
	for isPointer(obj) {
		v := reflect.ValueOf(obj)
		if v.IsNil() {
			return nil, false
		}
		obj = reflect.Indirect(v).Interface()
	}
	if obj == nil {
		return nil, false
	}
	return obj, true
}
resolvePointer keeps digging until it can't inspect any further or a
non-pointer is unearthed.
package metaflector
import (
	"reflect"
	"sort"
	"strings"
)
var Separator = "."
func TerminalFields(obj interface{}) []string {
	if obj == nil {
		return nil
	}
	type item struct {
		obj  interface{}
		path string
	}
	var (
		paths = []string{}
		queue = []item{
			{obj: obj},
		}
	)
	for len(queue) > 0 {
		EachField(queue[0].obj, func(child interface{}, name string, kind reflect.Kind) {
			if len(queue[0].path) > 0 {
				name = queue[0].path + Separator + name
			}
			if isTerminal(kind) {
				paths = append(paths, name)
			} else {
				i := item{
					obj:  child,
					path: name,
				}
				queue = append(queue, i)
			}
		})
		queue = queue[1:]
	}
	sort.Strings(paths)
	return paths
}
type IterFunc func(child interface{}, name string, kind reflect.Kind)
func EachField(obj interface{}, fn IterFunc) (ok bool) {
	if obj, ok = ResolveUnderlying(obj); !ok || obj == nil {
		ok = false
		return
	}
	v := reflect.ValueOf(obj)
	for i := 0; i < v.NumField(); i++ {
		if sf := v.Type().Field(i); sf.PkgPath != "" || sf.Anonymous {
			continue
		}
		var (
			field = v.Field(i)
			name  = v.Type().Field(i).Name
			kind  = field.Kind()
		)
		for kind == reflect.Ptr {
			kind = field.Type().Elem().Kind()
		}
		switch kind {
		case reflect.Struct:
			fn(field.Interface(), name, kind)
		case reflect.Slice, reflect.Array:
			if firstObj, ok := ResolveUnderlying(field.Interface()); ok {
				EachField(firstObj, func(child interface{}, childName string, childKind reflect.Kind) {
					fn(child, name+Separator+childName, childKind)
				})
			}
		case reflect.String, reflect.Float32, reflect.Float64, reflect.Bool, reflect.Map, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			fn(unreflect(field), name, kind)
		}
	}
	ok = true
	return
}
func ResolveUnderlying(obj interface{}) (resolved interface{}, ok bool) {
	if obj, ok = resolvePointer(obj); !ok {
		return
	}
	if hasType(obj, []reflect.Kind{reflect.Slice, reflect.Array}) {
		v := reflect.ValueOf(obj)
		if v.Len() == 0 {
			return
		}
		obj = nil
		for i := 0; i < v.Len(); i++ {
			if value := v.Index(i); isStruct(value.Interface()) || !value.IsNil() {
				obj = value.Interface()
				break
			}
		}
	}
	if obj, ok = resolvePointer(obj); !ok {
		return
	}
	if !isStruct(obj) {
		ok = false
		return
	}
	resolved = obj
	ok = true
	return
}