// FindEntityByName returns the entity with given name in the path.
764602
func FindEntityByName(path string, structName string) (*Table, error) {
	// find all entites in the given path
	entities, _, err := findEntities([]string{path}, []string{})
	if err != nil {
		return nil, err
	}

	// filter entites with the given struct name
	entitiesFilteredByName := []*Table{}
	for _, table := range entities {
		if table.StructName == structName {
			entitiesFilteredByName = append(entitiesFilteredByName, table)
		}
	}

	// only one entity with given name should be found
	if len(entitiesFilteredByName) == 0 {
		return nil, errors.Errorf("no entity named %s found in the path %s", structName, path)
	}
	if len(entitiesFilteredByName) > 1 {
		return nil, errors.Errorf("more than one entities named %s found in the path %s", structName, path)
	}

	return entitiesFilteredByName[0], nil
}
570778
func (st *State) FindEntity(tag names.Tag) (Entity, error) {
	id := tag.Id()
	switch tag := tag.(type) {
	case names.MachineTag:
		return st.Machine(id)
	case names.UnitTag:
		return st.Unit(id)
	case names.UserTag:
		return st.User(tag)
	case names.ApplicationTag:
		return st.Application(id)
	case names.ModelTag:
		model, err := st.Model()
		if err != nil {
			return nil, errors.Trace(err)
		}
		// Return an invalid entity error if the requested model is not
		// the current one.
		if id != model.UUID() {
			if utils.IsValidUUIDString(id) {
				return nil, errors.NotFoundf("model %q", id)
			}
			// TODO(axw) 2013-12-04 #1257587
			// We should not accept model tags that do not match the
			// model's UUID. We accept anything for now, to cater
			// both for past usage, and for potentially supporting aliases.
			logger.Warningf("model-tag does not match current model UUID: %q != %q", id, model.UUID())
			conf, err := model.ModelConfig()
			if err != nil {
				logger.Warningf("ModelConfig failed: %v", err)
			} else if id != conf.Name() {
				logger.Warningf("model-tag does not match current model name: %q != %q", id, conf.Name())
			}
		}
		return model, nil
	case names.RelationTag:
		return st.KeyRelation(id)
	case names.ActionTag:
		model, err := st.Model()
		if err != nil {
			return nil, errors.Trace(err)
		}
		return model.ActionByTag(tag)
	case names.CharmTag:
		if url, err := charm.ParseURL(id); err != nil {
			logger.Warningf("Parsing charm URL %q failed: %v", id, err)
			return nil, errors.NotFoundf("could not find charm %q in state", id)
		} else {
			return st.Charm(url)
		}
	case names.VolumeTag:
		sb, err := NewStorageBackend(st)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return sb.Volume(tag)
	case names.FilesystemTag:
		sb, err := NewStorageBackend(st)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return sb.Filesystem(tag)
	default:
		return nil, errors.Errorf("unsupported tag %T", tag)
	}
}
87419
func (s SearchIndex) FindByDnsName(ctx context.Context, dc *Datacenter, dnsName string, vmSearch bool) (Reference, error) {
	req := types.FindByDnsName{
		This:     s.Reference(),
		DnsName:  dnsName,
		VmSearch: vmSearch,
	}
	if dc != nil {
		ref := dc.Reference()
		req.Datacenter = &ref
	}

	res, err := methods.FindByDnsName(ctx, s.c, &req)
	if err != nil {
		return nil, err
	}

	if res.Returnval == nil {
		return nil, nil
	}
	return NewReference(s.c, *res.Returnval), nil
}
1370151
func FindById(i interface{}, id string) error {
	return Find(i, bson.M{"_id": bson.ObjectIdHex(id)})
}
90606
func (n *Node) GetChildByPath(subPath string) (*Node, error) {
	// Find the subnode if needed.
	parts := strings.Split(subPath, "/")

	currentNode := n
	for i := 0; i < len(parts); i++ {
		childPathName := parts[i]
		found := false
		for _, child := range currentNode.Children {
			if child.PathName == childPathName {
				found = true
				currentNode = child
				break
			}
		}
		if !found {
			return nil, fmt.Errorf("node %v has no children named %v", currentNode.Path, childPathName)
		}
	}
	return currentNode, nil
}
1263380
func (i *DocumentIndex) FindOrganizationByName(org string) (influxdb.ID, error) {
	o, err := i.service.findOrganizationByName(i.ctx, i.tx, org)
	if err != nil {
		return influxdb.InvalidID(), err
	}
	return o.ID, nil
}
173699
func (r *resourceRepository) FindByHostname(ctx context.Context, hostname string) (*resources.Resource, error) {
	r.mtx.RLock()
	defer r.mtx.RUnlock()
	resource, ok := r.resources[resourceHostname(hostname)]
	if !ok {
		return nil, resources.WithErrNotFound(errors.New("resource resource not found"))
	}
	return resource, nil
}
1234887
func (pm *VolumePluginMgr) FindMapperPluginByName(name string) (BlockVolumePlugin, error) {
	volumePlugin, err := pm.FindPluginByName(name)
	if err != nil {
		return nil, err
	}

	if blockVolumePlugin, ok := volumePlugin.(BlockVolumePlugin); ok {
		return blockVolumePlugin, nil
	}
	return nil, nil
}
828243
func (f *fields) GetByAny(name string) (*fieldInfo, bool) {
	if fi, ok := f.fields[name]; ok {
		return fi, ok
	}
	if fi, ok := f.fieldsLow[strings.ToLower(name)]; ok {
		return fi, ok
	}
	if fi, ok := f.columns[name]; ok {
		return fi, ok
	}
	return nil, false
}
169700
func (t *TeamsClient) GetByName(ctx context.Context, orgID *identity.ID, name string) ([]envelope.Team, error) {
	return t.List(ctx, orgID, name, primitive.AnyTeamType)
}
951489
func (s *ErrorRootCauseService) SetEntityPath(v []*ErrorRootCauseEntity) *ErrorRootCauseService {
	s.EntityPath = v
	return s
}
252540
func (c *ExampleService) FindUserByName(ctx context.Context, n string) (*platform.User, error) {
	var u *platform.User

	err := c.kv.View(func(tx Tx) error {
		usr, err := c.findUserByName(ctx, tx, n)
		if err != nil {
			return err
		}
		u = usr
		return nil
	})

	return u, err
}
1327866
func findEntities(paths, excludes []string) ([]*Table, []error, error) {
	var entities []*Table
	var warnings []error
	for _, path := range paths {
		fileSet := token.NewFileSet()
		packages, err := parser.ParseDir(fileSet, path, func(fileInfo os.FileInfo) bool {
			if len(excludes) == 0 {
				return true
			}
			for _, exclude := range excludes {
				if matched, _ := filepath.Match(exclude, fileInfo.Name()); matched {
					return false
				}
			}
			return true
		}, 0)
		if err != nil {
			return nil, nil, err
		}
		erv := new(entityRecordingVisitor)
		for _, pkg := range packages { // go through all the packages
			for _, file := range pkg.Files { // go through all the files
				packagePrefix, hasDosa := findDosaPackage(file)
				//if erv.PackageName != "" { // skip packages that don't import 'dosa'
				if hasDosa {
					erv.packagePrefix = packagePrefix
					for _, decl := range file.Decls { // go through all the declarations
						ast.Walk(erv, decl)
					}
				}
			}
		}
		entities = append(entities, erv.entities...)
		warnings = append(warnings, erv.warnings...)
	}

	return entities, warnings, nil
}
591926
func (s *partitionProcessor) findByName(partitionNames []model.CIStr, partitionName string) bool {
	for _, s := range partitionNames {
		if s.L == partitionName {
			return true
		}
	}
	return false
}
950241
func (ch *CredHub) FindByPath(path string) (credentials.FindResults, error) {
	return ch.findByPathOrNameLike("path", path)
}
616959
func (s *ResponseTimeRootCauseService) SetEntityPath(v []*ResponseTimeRootCauseEntity) *ResponseTimeRootCauseService {
	s.EntityPath = v
	return s
}
1095936
func (interactor GetSamplesInteractorImpl) AllByName(keyword string) ([]*SampleEntity, error) {
	keyword = strings.ToLower(keyword)
	var list []*SampleEntity
	for _, item := range interactor.Samples {
		name := item.NameLower()
		if strings.Contains(name, keyword) {
			list = append(list, item)
		}
	}
	if len(list) == 0 {
		return list, errors.New("Not Found")
	}
	return list, nil
}