//AddServices WARING, this function making alloc
//For the best performance, use AddService in a loop
333274
func (i *injector) AddServices(vals ...interface{}) {
	for _, v := range vals {
		i.AddService(v)
	}
}
1235075
func (s *GetTraceGraphOutput) SetServices(v []*Service) *GetTraceGraphOutput {
	s.Services = v
	return s
}
849646
func (s *Store) AddService(service string, config *discoverd.ServiceConfig) error {
	if config == nil {
		config = DefaultServiceConfig
	}

	// Serialize command.
	cmd, err := json.Marshal(&addServiceCommand{
		Service: service,
		Config:  config,
	})
	if err != nil {
		return err
	}

	if _, err := s.raftApply(addServiceCommandType, cmd); err != nil {
		return err
	}
	return err
}
317152
func (a *Agent) addServiceLocked(service *structs.NodeService, chkTypes []*structs.CheckType, persist bool, token string, source configSource) error {
	if err := a.validateService(service, chkTypes); err != nil {
		return err
	}

	if a.config.EnableCentralServiceConfig {
		return a.serviceManager.AddService(service, chkTypes, persist, token, source)
	}

	return a.addServiceInternal(service, chkTypes, persist, token, source)
}
970230
func (service *BaseService) AddFunction(name string, function interface{}, option ...Options) Service {
	service.methodManager.AddFunction(name, function, option...)
	return service
}
986172
func (s *Svc) AllFunctions() []*api.Function {
	var (
		functions []*api.Function
		added     = make(map[string]struct{})
		services  = append([]*Svc{s}, s.Parents...)
	)

	for _, s := range services {
		for _, f := range s.Functions {
			if _, taken := added[f.ThriftName]; taken {
				continue
			}

			functions = append(functions, f)
		}
	}

	return functions
}
959625
func (s *storeImpl) addUpdatedServicesFromCache(ctx datastore.Context, svcs []Service, since time.Time) ([]Service, error) {
	// Make a map of service ids so we don't duplicate services from our cache.
	svcMap := make(map[string]struct{})
	for _, svc := range svcs {
		svcMap[svc.ID] = struct{}{}
	}

	// If getting these one at a time turns out to be hard on elastic, we can
	// later try batching the elastic queries for sets of N ids until we go
	// through the whole list with a new elastic search.
	for _, cacheEntry := range s.getUpdatedCacheEntries(since) { // single Mutex RLock
		// Don't add services already in the list.
		if _, ok := svcMap[cacheEntry.ID]; !ok {
			// Query the service from elastic.  We already have the cached
			// data, so we save making a mutex lock here for every service
			// by called s.get() and updating the service without needing
			// additional mutex locks.
			if svc, err := s.get(ctx, cacheEntry.ID); err != nil {
				return svcs, err
			} else {
				// Fill additional info without a mutex lock.
				s.fillConfig(svc)
				s.updateServiceFromVolatileService(svc, cacheEntry)
				svcs = append(svcs, *svc)
			}
		} else {
			plog.WithField("serviceid", cacheEntry.ID).Debug("Skipping service because it is already cached")
		}
	}
	return svcs, nil
}
55400
func (w *Watchdog) AddService(name, binary string) (*Service, error) {
	if _, ok := w.services[name]; ok {
		return nil, fmt.Errorf("Service %q already exists", name)
	}

	svc := newService(name, binary)
	w.services[name] = svc

	return svc, nil
}
1076887
func (s *Server) initializeServices() error {
	serviceNames, err := s.Store.List("/services/")
	if err != nil {
		return err
	}
	for _, serviceName := range serviceNames {
		service := Service{}
		if err := s.Store.Get(fmt.Sprintf("/services/%s", serviceName), &service); err != nil {
			return err
		}

		s.idpConfigMu.Lock()
		s.serviceProviders[service.Metadata.EntityID] = &service.Metadata
		s.idpConfigMu.Unlock()
	}
	return nil
}
902176
func (_m *Balancer) AddService(_a0 *types.Service) error {
	ret := _m.Called(_a0)

	var r0 error
	if rf, ok := ret.Get(0).(func(*types.Service) error); ok {
		r0 = rf(_a0)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
314278
func (state *ServicesState) ProcessServiceMsgs(looper director.Looper) {
	looper.Loop(func() error {
		service := <-state.ServiceMsgs
		state.AddServiceEntry(service)
		return nil
	})
}
374217
func (s *serviceLister) Services(namespace string) ServiceNamespaceLister {
	return serviceNamespaceLister{indexer: s.indexer, namespace: namespace}
}
403969
func (s *ServiceCache) addPorts(e *common.Service, record *entry, local bool) error {
	if !local {
		return nil
	}

	for _, spec := range s.localPorts {
		if spec.ports.Overlaps(e.Ports) {
			return fmt.Errorf("service port overlap in the global port list: %+v %s", e.Addresses, e.Ports.String())
		}
	}

	s.localPorts = append(s.localPorts, record)

	return nil
}
1324819
func (w *upgradeSeriesWorker) unitServices() (map[string]string, error) {
	services, err := w.service.ListServices()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return service.FindUnitServiceNames(services), nil
}
1288576
func AddServiceTCP(configuration *config.TCPConfiguration, serviceName string, service *config.TCPService) bool {
	if _, ok := configuration.Services[serviceName]; !ok {
		configuration.Services[serviceName] = service
		return true
	}

	if !configuration.Services[serviceName].LoadBalancer.Mergeable(service.LoadBalancer) {
		return false
	}

	configuration.Services[serviceName].LoadBalancer.Servers = append(configuration.Services[serviceName].LoadBalancer.Servers, service.LoadBalancer.Servers...)
	return true
}
841042
func (ctx *Context) ListServices() ([]string, error) {
	ctx.mutex.RLock()
	defer ctx.mutex.RUnlock()

	r := make([]string, 0, len(ctx.services))

	for vsID := range ctx.services {
		r = append(r, vsID)
	}

	return r, nil
}
1015908
func Services(s map[string][]*registry.Service) registry.Option {
	return func(o *registry.Options) {
		if o.Context == nil {
			o.Context = context.Background()
		}
		o.Context = context.WithValue(o.Context, servicesKey{}, s)
	}
}