// NewSigsHandler creates a SigsHandler for the xp transport.
339981
func NewSigsHandler(xp rpc.Transporter, g *libkb.GlobalContext) *SigsHandler {
	return &SigsHandler{
		BaseHandler:  NewBaseHandler(g, xp),
		Contextified: libkb.NewContextified(g),
	}
}
130391
func HeadersHandler(w http.ResponseWriter, r *http.Request) {
	if err := writeJSON(w, headersResponse{getHeaders(r)}); err != nil {
		writeErrorJSON(w, errors.Wrap(err, "failed to write json"))
	}
}
55918
func FSContextHandler(fs *FS, fail http.HandlerFunc) FlatHandler {
	fsh := FSHandler(fs, fail)
	return func(c *Context, next NextHandler) {
		fsh(c.Res, c.Req, c.c)
		next(c)
	}
}
719014
func (wi *Instance) InstallSignalHandlers() {
	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
	go func() {
		for s := range sigChan {
			// We got a signal, notify our modules.
			// Use an extra function to properly unlock using defer.
			func() {
				wi.currentWorkerMutex.Lock()
				defer wi.currentWorkerMutex.Unlock()
				if wi.currentCancelFunc != nil {
					log.Infof("Trying to cancel current worker after receiving signal: %v", s)
					wi.currentCancelFunc()
				} else {
					log.Infof("Shutting down idle worker after receiving signal: %v", s)
					os.Exit(0)
				}
			}()
		}
	}()
}
662765
func NewSigsList(g *libkb.GlobalContext, args SigsListArgs) *SigsList {
	return &SigsList{
		SigsListArgs: args,
		Contextified: libkb.NewContextified(g),
	}
}
78408
func newScanModelsHandler(spec *modelSpec, fieldNames []string, models interface{}) ReplyHandler {
	return func(reply interface{}) error {
		allFields, err := redis.Values(reply, nil)
		modelsVal := reflect.ValueOf(models).Elem()
		if err != nil {
			if err == redis.ErrNil {
				// This means no models matched the criteria. Set the length of
				// models to 0 to indicate this and then return.
				modelsVal.SetLen(0)
				return nil
			}
			return err
		}
		numFields := len(fieldNames)
		numModels := len(allFields) / numFields
		for i := 0; i < numModels; i++ {
			start := i * numFields
			stop := i*numFields + numFields
			fieldValues := allFields[start:stop]
			var modelVal reflect.Value
			if modelsVal.Len() > i {
				// Use the pre-existing value at index i
				modelVal = modelsVal.Index(i)
				if modelVal.IsNil() {
					// If the value is nil, allocate space for it
					modelsVal.Index(i).Set(reflect.New(spec.typ.Elem()))
				}
			} else {
				// Index i is out of range of the existing slice. Create a
				// new modelVal and append it to modelsVal
				modelVal = reflect.New(spec.typ.Elem())
				modelsVal.Set(reflect.Append(modelsVal, modelVal))
			}
			mr := &modelRef{
				spec:  spec,
				model: modelVal.Interface().(Model),
			}
			if err := scanModel(fieldNames, fieldValues, mr); err != nil {
				return err
			}
		}
		// Trim the slice if it is longer than the number of models we scanned
		// in.
		if numModels < modelsVal.Len() {
			modelsVal.SetLen(numModels)
			modelsVal.SetCap(numModels)
		}
		return nil
	}
}
1102420
func NewSigner(conf Config) (*Signer, error) {
	sId, err := serializeIdentity(conf.IdentityPath, conf.MSPID)
	if err != nil {
		return nil, errors.WithStack(err)
	}
	key, err := loadPrivateKey(conf.KeyPath)
	if err != nil {
		return nil, errors.WithStack(err)
	}
	return &Signer{
		Creator: sId,
		key:     key,
	}, nil
}
665120
func NewSimpleSender(addr string) (Sender, error) {
	c, err := net.ListenPacket("udp", ":0")
	if err != nil {
		return nil, err
	}

	ra, err := net.ResolveUDPAddr("udp", addr)
	if err != nil {
		c.Close()
		return nil, err
	}

	sender := &SimpleSender{
		c:  c,
		ra: ra,
	}

	return sender, nil
}
1206923
func NewSyslogHandlerToAddr(
	network, raddr string,
	priority syslog.Priority,
	tag string) (*SyslogHandler, error) {

	writer, err := syslog.Dial(network, raddr, priority, tag)
	if err != nil {
		return nil, err
	}
	object := &SyslogHandler{
		BaseHandler: NewBaseHandler("", LevelNotset),
		network:     network,
		raddr:       raddr,
		priority:    priority,
		tag:         tag,
		writer:      writer,
	}
	return object, nil
}
452052
func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Request) {
	wsConn, err := wm.Upgrade(w, r, nil)
	if err != nil {
		// TODO - return http error
		wm.logger.TraceMsg("Failed to upgrade to websocket connection", structure.ErrorKey, err)
		return
	}

	// register connection
	con := NewWSConnection(wsConn, wm.funcMap, wm.logger, wm.wsConnOptions...)
	wm.logger.InfoMsg("New websocket connection", "remote_address", con.remoteAddr)
	err = con.Start() // Blocking
	if err != nil {
		wm.logger.TraceMsg("Error starting connection", structure.ErrorKey, err)
	}
}
277811
func installSignalHandlers(cancel func()) {
	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
	go func() {
		<-sigChan
		// we got a signal, cancel the current ctx
		cancel()
	}()
}
505561
func NewSignerFromSigner(signer crypto.Signer) (Signer, error) {
	pubKey, err := NewPublicKey(signer.Public())
	if err != nil {
		return nil, err
	}

	return &wrappedSigner{signer, pubKey}, nil
}
82997
func NewSocketHandler(host string, port uint16) *SocketHandler {
	retry := NewErrorRetry().
		Delay(SocketDefaultDelay).
		Deadline(SocketDefaultMaxDeadline)
	object := &SocketHandler{
		BaseHandler:  NewBaseHandler("", LevelNotset),
		host:         host,
		port:         port,
		closeOnError: true,
		retry:        retry,
	}
	object.makeConnFunc = object.makeTCPSocket
	object.sendFunc = object.sendTCP
	Closer.AddHandler(object)
	return object
}
316131
func (ref *Consumer) notificationHandler(in <-chan *cluster.Notification) {
	ref.Debug("NotificationHandler started ...")

	for {
		select {
		case note := <-in:
			ref.Config.RecvNotificationChan <- note
		case <-ref.closeChannel:
			ref.Debug("Canceling notification handler")
			return
		}
	}
}
784245
func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
	if err := os.MkdirAll(root, 0700); err != nil {
		return nil, err
	}
	ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db"))
	if err != nil {
		return nil, err
	}

	if err := os.Mkdir(filepath.Join(root, "snapshots"), 0700); err != nil && !os.IsExist(err) {
		return nil, err
	}

	return &snapshotter{
		root: root,
		ms:   ms,
	}, nil
}
600066
func NewSimpleRouter(fe, be core.Stream) Router {
	return &simpleRouter{
		backendPid: 0,
		secretKey:  0,
		fe:         fe,
		be:         be,
	}
}
109240
func NewSourceHandler() *SourceHandler {
	h := &SourceHandler{
		Router: NewRouter(),
		Logger: zap.NewNop(),
		NewBucketService: func(s *platform.Source) (platform.BucketService, error) {
			return nil, fmt.Errorf("bucket service not set")
		},
		NewQueryService: func(s *platform.Source) (query.ProxyQueryService, error) {
			return nil, fmt.Errorf("query service not set")
		},
	}

	h.HandlerFunc("POST", "/api/v2/sources", h.handlePostSource)
	h.HandlerFunc("GET", "/api/v2/sources", h.handleGetSources)
	h.HandlerFunc("GET", "/api/v2/sources/:id", h.handleGetSource)
	h.HandlerFunc("PATCH", "/api/v2/sources/:id", h.handlePatchSource)
	h.HandlerFunc("DELETE", "/api/v2/sources/:id", h.handleDeleteSource)

	h.HandlerFunc("GET", "/api/v2/sources/:id/buckets", h.handleGetSourcesBuckets)
	h.HandlerFunc("POST", "/api/v2/sources/:id/query", h.handlePostSourceQuery)
	h.HandlerFunc("GET", "/api/v2/sources/:id/health", h.handleGetSourceHealth)

	return h
}