func()

in pkg/cloud/api/path.go [175:208]


func (p Path) ResolveType(t reflect.Type) (reflect.Type, error) {
	for i, x := range p {
		switch x[0] {
		case pathField:
			if t.Kind() != reflect.Struct {
				return nil, fmt.Errorf("at %s element %d, expected struct, got %s", p, i, t)
			}
			fieldName := x[1:]
			sf, ok := t.FieldByName(fieldName)
			if !ok {
				return nil, fmt.Errorf("at %s element %d, no field named %q", p, i, fieldName)
			}
			t = sf.Type
		case pathSliceIndex:
			if t.Kind() != reflect.Slice {
				return nil, fmt.Errorf("at %s element %d, expected slice, got %s", p, i, t)
			}
			t = t.Elem()
		case pathMapIndex:
			if t.Kind() != reflect.Map {
				return nil, fmt.Errorf("at %s element %d, expected map, got %s", p, i, t)
			}
			t = t.Elem()
		case pathPointer:
			if t.Kind() != reflect.Pointer {
				return nil, fmt.Errorf("at %s element %d, expected pointer, got %s", p, i, t)
			}
			t = t.Elem()
		default:
			return nil, fmt.Errorf("at %s element %d, invalid path type %q", p, i, x[0])
		}
	}
	return t, nil
}