// NewWebService creates a new restful webservice with the api installer's prefix and version.
13226
func (a *MetricsAPIInstaller) NewWebService() *restful.WebService {
	ws := new(restful.WebService)
	ws.Path(a.prefix)
	// a.prefix contains "prefix/group/version"
	ws.Doc("API at " + a.prefix)
	// Backwards compatibility, we accepted objects with empty content-type at V1.
	// If we stop using go-restful, we can default empty content-type to application/json on an
	// endpoint by endpoint basis
	ws.Consumes("*/*")
	mediaTypes, streamMediaTypes := negotiation.MediaTypesForSerializer(a.group.Serializer)
	ws.Produces(append(mediaTypes, streamMediaTypes...)...)
	ws.ApiVersion(a.group.GroupVersion.String())

	return ws
}
1316362
func NewExplainService(client *Client) *ExplainService {
	return &ExplainService{
		client:         client,
		typ:            "_doc",
		xSource:        make([]string, 0),
		xSourceExclude: make([]string, 0),
		fields:         make([]string, 0),
		xSourceInclude: make([]string, 0),
	}
}
962890
func NewBrowser(ctx context.Context, urlstr string, opts ...BrowserOption) (*Browser, error) {
	b := &Browser{
		LostConnection: make(chan struct{}),

		newTabQueue: make(chan *Target),
		delTabQueue: make(chan target.SessionID, 1),

		// Fit some jobs without blocking, to reduce blocking in
		// Execute.
		cmdQueue: make(chan cmdJob, 32),

		logf: log.Printf,
	}
	// apply options
	for _, o := range opts {
		o(b)
	}
	// ensure errf is set
	if b.errf == nil {
		b.errf = func(s string, v ...interface{}) { b.logf("ERROR: "+s, v...) }
	}

	// dial
	var err error
	urlstr = forceIP(urlstr)
	b.conn, err = DialContext(ctx, urlstr, WithConnDebugf(b.dbgf))
	if err != nil {
		return nil, fmt.Errorf("could not dial %q: %v", urlstr, err)
	}

	go b.run(ctx)
	return b, nil
}
348869
func NewAuthzService(config auth.ServiceConfiguration) *AuthzRoleService {
	return &AuthzRoleService{Config: config, Doer: rest.DefaultHttpDoer()}
}
464554
func newIPVSService(svc *Service) *ipvsService {
	ipvsSvc := &ipvsService{
		Address:           svc.Address,
		Protocol:          svc.Protocol,
		Port:              svc.Port,
		FirewallMark:      svc.FirewallMark,
		Scheduler:         svc.Scheduler,
		Flags:             svc.Flags,
		Timeout:           svc.Timeout,
		PersistenceEngine: svc.PersistenceEngine,
	}

	if ip4 := svc.Address.To4(); ip4 != nil {
		ipvsSvc.AddrFamily = syscall.AF_INET
		ipvsSvc.Netmask = 0xffffffff
	} else {
		ipvsSvc.AddrFamily = syscall.AF_INET6
		ipvsSvc.Netmask = 128
	}

	return ipvsSvc
}
1305845
func NewAuthorizationService() *AuthorizationService {
	return &AuthorizationService{
		FindAuthorizationByIDFn:    func(context.Context, platform.ID) (*platform.Authorization, error) { return nil, nil },
		FindAuthorizationByTokenFn: func(context.Context, string) (*platform.Authorization, error) { return nil, nil },
		FindAuthorizationsFn: func(context.Context, platform.AuthorizationFilter, ...platform.FindOptions) ([]*platform.Authorization, int, error) {
			return nil, 0, nil
		},
		CreateAuthorizationFn:    func(context.Context, *platform.Authorization) error { return nil },
		DeleteAuthorizationFn:    func(context.Context, platform.ID) error { return nil },
		SetAuthorizationStatusFn: func(context.Context, platform.ID, platform.Status) error { return nil },
	}
}
535411
func NewLoggingService(logger log.Logger, s Service) Service {
	return &loggingService{logger, s}
}
767163
func (ens *NetpluginNameServer) AddLbService(tenant string, name string, v4name string) {
	if len(v4name) > 0 {
		dnsLog.Infof("add k8s service %s ip %s", name, v4name)
		if tenant == K8sDefaultTenant {
			ens.k8sService.Set(name, nameRecord{v4Record: net.ParseIP(v4name)})
		} else {
			mc := mastercfg.CfgServiceLBState{
				Tenant:      tenant,
				ServiceName: name,
				IPAddress:   v4name,
			}
			ens.addService(&mc)
		}
	}
}
159492
func NewBucketService(s platform.BucketService, engine BucketDeleter) *BucketService {
	return &BucketService{
		inner:  s,
		engine: engine,
	}
}
363410
func newMailService() {
	sec := Cfg.Section("mailer")
	if !sec.Key("ENABLED").MustBool() {
		return
	}

	MailService = &Mailer{
		QueueLength:     sec.Key("SEND_BUFFER_LEN").MustInt(100),
		SubjectPrefix:   sec.Key("SUBJECT_PREFIX").MustString("[" + AppName + "] "),
		Host:            sec.Key("HOST").String(),
		User:            sec.Key("USER").String(),
		Passwd:          sec.Key("PASSWD").String(),
		DisableHelo:     sec.Key("DISABLE_HELO").MustBool(),
		HeloHostname:    sec.Key("HELO_HOSTNAME").String(),
		SkipVerify:      sec.Key("SKIP_VERIFY").MustBool(),
		UseCertificate:  sec.Key("USE_CERTIFICATE").MustBool(),
		CertFile:        sec.Key("CERT_FILE").String(),
		KeyFile:         sec.Key("KEY_FILE").String(),
		UsePlainText:    sec.Key("USE_PLAIN_TEXT").MustBool(),
		AddPlainTextAlt: sec.Key("ADD_PLAIN_TEXT_ALT").MustBool(),
	}
	MailService.From = sec.Key("FROM").MustString(MailService.User)

	if len(MailService.From) > 0 {
		parsed, err := mail.ParseAddress(MailService.From)
		if err != nil {
			log.Fatal(2, "Invalid mailer.FROM (%s): %v", MailService.From, err)
		}
		MailService.FromEmail = parsed.Address
	}

	if HookMode {
		return
	}
	log.Info("Mail Service Enabled")
}
519120
func UpdateService(fe ServiceKey, backends []ServiceValue,
	addRevNAT bool, revNATID int,
	isLegacySVCEnabled bool,
	acquireBackendID func(loadbalancer.L3n4Addr) (loadbalancer.BackendID, error),
	releaseBackendID func(loadbalancer.BackendID)) error {

	var (
		weights         []uint16
		nNonZeroWeights uint16
	)

	// Find out which backends are new (i.e. the ones which do not exist yet and
	// will be created in this function) and acquire IDs for them
	newBackendIDs, err := acquireNewBackendIDs(backends, acquireBackendID)
	if err != nil {
		return err
	}

	// Store mapping of backend addr ID => backend ID in the cache
	cache.addBackendIDs(newBackendIDs)

	// Prepare the service cache for the updates
	svc, addedBackends, removedBackendIDs, err := cache.prepareUpdate(fe, backends)
	if err != nil {
		return err
	}

	// FIXME(brb) Uncomment the following code after we have enabled weights
	// in the BPF datapath code.
	//for _, be := range besValues {
	//	weights = append(weights, be.GetWeight())
	//	if be.GetWeight() != 0 {
	//		nNonZeroWeights++
	//	}
	//}

	mutex.Lock()
	defer mutex.Unlock()

	besValuesV2 := svc.getBackendsV2()

	log.WithFields(logrus.Fields{
		"frontend": fe,
		"backends": besValuesV2,
	}).Debugf("Updating BPF representation of service")

	// Add the new backends to the BPF maps
	if err := updateBackendsLocked(addedBackends); err != nil {
		return err
	}

	if isLegacySVCEnabled {
		besValues := svc.getBackends()
		// Update the legacy service BPF maps
		if err := updateServiceLegacyLocked(fe, besValues, addRevNAT, revNATID,
			weights, nNonZeroWeights); err != nil {
			return err
		}
	}

	// Update the v2 service BPF maps
	if err := updateServiceV2Locked(fe, besValuesV2, svc, addRevNAT, revNATID,
		weights, nNonZeroWeights, isLegacySVCEnabled); err != nil {
		return err
	}

	// Delete no longer needed backends
	if err := removeBackendsLocked(removedBackendIDs, fe.IsIPv6(),
		releaseBackendID); err != nil {
		return err
	}

	return nil
}
151573
func NewService(name string, serviceConfig *config.ServiceConfig, context *ctx.Context) *Service {
	return &Service{
		name:          name,
		project:       context.Project,
		serviceConfig: serviceConfig,
		clientFactory: context.ClientFactory,
		authLookup:    context.AuthLookup,
		context:       context,
	}
}
711406
func (c Client) New(params *stripe.WebhookEndpointParams) (*stripe.WebhookEndpoint, error) {
	endpoint := &stripe.WebhookEndpoint{}
	err := c.B.Call(http.MethodPost, "/v1/webhook_endpoints", c.Key, params, endpoint)
	return endpoint, err
}
349903
func (s *legacyRootAPIHandler) WebService() *restful.WebService {
	mediaTypes, _ := negotiation.MediaTypesForSerializer(s.serializer)
	ws := new(restful.WebService)
	ws.Path(s.apiPrefix)
	ws.Doc("get available API versions")
	ws.Route(ws.GET("/").To(s.handle).
		Doc("get available API versions").
		Operation("getAPIVersions").
		Produces(mediaTypes...).
		Consumes(mediaTypes...).
		Writes(metav1.APIVersions{}))
	return ws
}
821258
func NewGetMappingService(client *Client) *GetMappingService {
	return &GetMappingService{
		client: client,
		index:  make([]string, 0),
		typ:    make([]string, 0),
	}
}
212495
func NewAWSService() AWSService {
	s := session.New(&aws.Config{Region: &awsRegion})

	return &RealAWSService{
		elbc: elb.New(s),
		r53c: route53.New(s),
		ec2:  ec2.New(s),
	}
}
1212695
func (s *Server) AddService(svc *ble.Service) error {
	s.Lock()
	defer s.Unlock()
	s.svcs = append(s.svcs, svc)
	s.db = att.NewDB(s.svcs, uint16(1)) // ble attrs start at 1
	return nil
}