// LookupInstance resolves a service by its service instance name.
767347
func LookupInstance(ctx context.Context, instance string) (Service, error) {
	var srv Service

	conn, err := NewMDNSConn()
	if err != nil {
		return srv, err
	}

	return lookupInstance(ctx, instance, conn)
}
332349
func getInstance(key lazycache.Key, reload bool) (*ContextHandle, error) {

	once.Do(func() {
		ctxCache = newCtxCache()
		//anyway, loading first time, no need to reload
		reload = false
	})

	if reload {
		ctxCache.Delete(key)
	}

	ref, err := ctxCache.Get(key)
	if err != nil {
		return nil, errors.WithMessage(err, "failed to get pkcs11 ctx cache for given key")
	}

	return ref.(*ContextHandle), nil
}
20561
func (c *Client) LookupSubscription(subID string) (*SubscriptionRequest, error) {
	s, err := c.subscriptions.lookupBySubscriptionID(subID)
	if err != nil {
		return nil, err
	}
	return s.Request, nil
}
1174229
func (i *injector) GetService(t reflect.Type) reflect.Value {
	v := i.services[t]

	if v.IsValid() {
		return returnService(v)
	}

	if t.Kind() == reflect.Interface {
		for tp, val := range i.services {
			if tp.Implements(t) {
				if val.IsValid() {
					return returnService(val)
				}
			}
		}
	}

	if i.parent != nil {
		v = i.parent.GetService(t)
	}

	return returnService(v)
}
144254
func LookupSRV(service string, proto string, name string, resolver func(string, string, string) (string, []*net.SRV, error)) (string, []*net.SRV, error) {
	mu.Lock()
	defer mu.Unlock()

	var err error

	q := query{service, proto, name}

	cname, addrs := retrieve(q)
	if addrs == nil {
		cname, addrs, err = resolver("", "", name)
	}

	store(q, cname, addrs)

	srvctr.WithLabelValues(identity).Inc()

	return cname, addrs, err
}
1207999
func (fcomp *fcomp) lookup(id *syntax.Ident) {
	switch resolve.Scope(id.Scope) {
	case resolve.Local:
		fcomp.setPos(id.NamePos)
		fcomp.emit1(LOCAL, uint32(id.Index))
	case resolve.Free:
		fcomp.emit1(FREE, uint32(id.Index))
	case resolve.Global:
		fcomp.setPos(id.NamePos)
		fcomp.emit1(GLOBAL, uint32(id.Index))
	case resolve.Predeclared:
		fcomp.setPos(id.NamePos)
		fcomp.emit1(PREDECLARED, fcomp.pcomp.nameIndex(id.Name))
	case resolve.Universal:
		fcomp.emit1(UNIVERSAL, fcomp.pcomp.nameIndex(id.Name))
	default:
		log.Fatalf("%s: compiler.lookup(%s): scope = %d", id.NamePos, id.Name, id.Scope)
	}
}
1073599
func (s *Server) lookupAccount(name string) (*Account, error) {
	if v, ok := s.accounts.Load(name); ok {
		acc := v.(*Account)
		// If we are expired and we have a resolver, then
		// return the latest information from the resolver.
		if acc.IsExpired() {
			var err error
			s.mu.Lock()
			if s.accResolver != nil {
				err = s.updateAccount(acc)
			}
			s.mu.Unlock()
			if err != nil {
				return nil, err
			}
		}
		return acc, nil
	}
	// If we have a resolver see if it can fetch the account.
	if s.accResolver == nil {
		return nil, ErrMissingAccount
	}
	s.mu.Lock()
	acc, err := s.fetchAccount(name)
	s.mu.Unlock()
	return acc, err
}
1181758
func (svc *googleService) getInstance() (*googlecloud.Instance, error) {
	return svc.service.Instances.Get(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do()
}
425510
func (m *GormResourceTypeRepository) Lookup(ctx context.Context, name string) (*ResourceType, error) {
	defer goa.MeasureSince([]string{"goa", "db", "resource_type", "lookupOrCreate"}, time.Now())

	var native ResourceType
	err := m.db.Table(m.TableName()).Where("name = ?", name).First(&native).Error
	if err == gorm.ErrRecordNotFound {
		return nil, errors.NewNotFoundErrorWithKey("resource_type", "name", name)
	}
	return &native, err
}
1010081
func (o *OrganizationLookup) Lookup(ctx context.Context, name string) (platform.ID, bool) {
	org, err := o.OrganizationService.FindOrganization(
		ctx,
		platform.OrganizationFilter{Name: &name},
	)

	if err != nil {
		return platform.InvalidID(), false
	}
	return org.ID, true
}
469330
func Lookup(name string) ChainingPlugin {
	mutex.RLock()
	defer mutex.RUnlock()

	return chainingPlugins[name]
}
1216439
func (indom *PCPInstanceDomain) MatchInstances(ins []string) bool {
	if len(ins) != len(indom.instances) {
		return false
	}

	for _, i := range ins {
		if _, ok := indom.instances[i]; !ok {
			return false
		}
	}

	return true
}
114626
func serviceToInstance(service *registry.Service) (*fargo.Instance, error) {
	if len(service.Nodes) == 0 {
		return nil, errors.New("Require nodes")
	}

	node := service.Nodes[0]

	instance := &fargo.Instance{
		App:              service.Name,
		HostName:         node.Address,
		IPAddr:           node.Address,
		VipAddress:       node.Address,
		SecureVipAddress: node.Address,
		Port:             node.Port,
		Status:           fargo.UP,
		UniqueID: func(i fargo.Instance) string {
			return fmt.Sprintf("%s:%s", node.Address, node.Id)
		},
		DataCenterInfo: fargo.DataCenterInfo{Name: fargo.MyOwn},
	}

	// set version
	instance.SetMetadataString("version", service.Version)

	// set instance ID
	instance.SetMetadataString("instanceId", node.Id)

	// set endpoints
	if b, err := json.Marshal(service.Endpoints); err == nil {
		instance.SetMetadataString("endpoints", string(b))
	}

	// set metadata
	if b, err := json.Marshal(node.Metadata); err == nil {
		instance.SetMetadataString("metadata", string(b))
	}

	return instance, nil
}
430305
func (m *KopsModelContext) FindInstanceGroup(name string) *kops.InstanceGroup {
	for _, ig := range m.InstanceGroups {
		if ig.ObjectMeta.Name == name {
			return ig
		}
	}
	return nil
}
1334225
func (m *Maestro) GetServiceName() (string, error) {
	address := m.osGetenv("SERVICE_NAME")
	if address == "" {
		return "", ErrNoServiceName
	}
	return address, nil
}
896189
func (dnsClient *DNSClientImpl) LookupMX(ctx context.Context, hostname string) ([]string, error) {
	dnsType := dns.TypeMX
	r, err := dnsClient.exchangeOne(ctx, hostname, dnsType)
	if err != nil {
		return nil, &DNSError{dnsType, hostname, err, -1}
	}
	if r.Rcode != dns.RcodeSuccess {
		return nil, &DNSError{dnsType, hostname, nil, r.Rcode}
	}

	var results []string
	for _, answer := range r.Answer {
		if mx, ok := answer.(*dns.MX); ok {
			results = append(results, mx.Mx)
		}
	}

	return results, nil
}
1163475
func (r *ClearNet) LookupSRV(service, proto, name string) (string, []*net.SRV, error) {
	return net.LookupSRV(service, proto, name)
}