// NewImportTracker creates an empty Import tracker instance
502605
func NewImportTracker() *ImportTracker {
	return &ImportTracker{
		make(map[string]string),
		make(map[string]string),
		make(map[string]bool),
	}
}
874849
func GetImportFunc(ctx context.Context) store.ImportCallback {
	imf, ok := ctx.Value(ctxKeyImportFunc).(store.ImportCallback)
	if !ok || imf == nil {
		return func(context.Context, string, []string) bool {
			return true
		}
	}
	return imf
}
1066735
func addImports(imports map[string]string, decl ast.Decl, srcDir string) {
	genDecl, ok := decl.(*ast.GenDecl)
	if !ok {
		return
	}

	if genDecl.Tok != token.IMPORT {
		return
	}

	for _, spec := range genDecl.Specs {
		importSpec := spec.(*ast.ImportSpec)
		var pkgAlias string
		if importSpec.Name != nil {
			pkgAlias = importSpec.Name.Name
			if pkgAlias == "_" {
				continue
			}
		}
		quotedPath := importSpec.Path.Value           // e.g. "\"sample/app/models\""
		fullPath := quotedPath[1 : len(quotedPath)-1] // Remove the quotes

		// If the package was not aliased (common case), we have to import it
		// to see what the package name is.
		// TODO: Can improve performance here a lot:
		// 1. Do not import everything over and over again.  Keep a cache.
		// 2. Exempt the standard library; their directories always match the package name.
		// 3. Can use build.FindOnly and then use parser.ParseDir with mode PackageClauseOnly
		if pkgAlias == "" {
			utils.Logger.Debug("Reading from build", "path", fullPath, "srcPath", srcDir, "gopath", build.Default.GOPATH)
			pkg, err := build.Import(fullPath, srcDir, 0)
			if err != nil {
				// We expect this to happen for apps using reverse routing (since we
				// have not yet generated the routes).  Don't log that.
				if !strings.HasSuffix(fullPath, "/app/routes") {
					utils.Logger.Error("Could not find import:", "path", fullPath, "srcPath", srcDir, "error", err)
				}
				continue
			} else {
				utils.Logger.Debug("Found package in dir", "dir", pkg.Dir, "name", pkg.ImportPath)
			}
			pkgAlias = pkg.Name
		}

		imports[pkgAlias] = fullPath
	}
}
301073
func newFlagTracker(flagger Flagger) *flagTracker {
	fTr := &flagTracker{
		flagger: flagger,
		shorts: map[rune]struct{}{
			'h': {}, // "h" is always used for help, so we can't set it.
		},
	}
	fTr.pflagger, fTr.pflag = flagger.(PFlagger)
	return fTr
}
824254
func NewMigrationBox(box packd.Walkable, c *Connection) (MigrationBox, error) {
	fm := MigrationBox{
		Migrator: NewMigrator(c),
		Box:      box,
	}

	err := fm.findMigrations()
	if err != nil {
		return fm, errors.WithStack(err)
	}

	return fm, nil
}
977357
func NewImportCommand(stdin io.Reader, stdout, stderr io.Writer) *ImportCommand {
	return &ImportCommand{
		CmdIO:      pilosa.NewCmdIO(stdin, stdout, stderr),
		BufferSize: 10000000,
	}
}
1105595
func NewExporter(uri string, sslVerify bool, selectedServerMetrics map[int]*prometheus.Desc, timeout time.Duration) (*Exporter, error) {
	u, err := url.Parse(uri)
	if err != nil {
		return nil, err
	}

	var fetch func() (io.ReadCloser, error)
	switch u.Scheme {
	case "http", "https", "file":
		fetch = fetchHTTP(uri, sslVerify, timeout)
	case "unix":
		fetch = fetchUnix(u, timeout)
	default:
		return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme)
	}

	return &Exporter{
		URI:   uri,
		fetch: fetch,
		up: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "up",
			Help:      "Was the last scrape of haproxy successful.",
		}),
		totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Name:      "exporter_total_scrapes",
			Help:      "Current total HAProxy scrapes.",
		}),
		csvParseFailures: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Name:      "exporter_csv_parse_failures",
			Help:      "Number of errors while parsing CSV.",
		}),
		serverMetrics: selectedServerMetrics,
	}, nil
}
967274
func (c Configuration) InitGlobalTracer(
	serviceName string,
	options ...Option,
) (io.Closer, error) {
	if c.Disabled {
		return &nullCloser{}, nil
	}
	tracer, closer, err := c.New(serviceName, options...)
	if err != nil {
		return nil, err
	}
	opentracing.SetGlobalTracer(tracer)
	return closer, nil
}
549931
func NewCounterFrom(opts prometheus.CounterOpts, labelNames []string) *Counter {
	cv := prometheus.NewCounterVec(opts, labelNames)
	prometheus.MustRegister(cv)
	return NewCounter(cv)
}
190037
func NewPaperAdminExportStartType(Description string) *PaperAdminExportStartType {
	s := new(PaperAdminExportStartType)
	s.Description = Description
	return s
}
54249
func NewExporter(opts ...Option) (*Exporter, error) {
	c := defaultConfig()
	for _, opt := range opts {
		opt(c)
	}

	tracer := lightstep.NewTracer(c.tracerOptions)
	if tracer == nil {
		if err := c.tracerOptions.Validate(); err != nil {
			return nil, err
		}
		return nil, ErrFailedToCreateExporter
	}

	return &Exporter{
		tracer: tracer,
	}, nil
}
45609
func createImport(name, path string) *ast.ImportSpec {
	return &ast.ImportSpec{
		Name: &ast.Ident{Name: name},
		Path: &ast.BasicLit{Kind: 9, Value: path},
	}
}
1026385
func New(currentpkg string) Importer {
	return &imports{
		currentpkg: currentpkg,
		imp:        make(map[string]string),
	}
}
419693
func newCostTracker(db ethdb.Database, config *eth.Config) *costTracker {
	utilTarget := float64(config.LightServ) * flowcontrol.FixedPointMultiplier / 100
	ct := &costTracker{
		db:         db,
		stopCh:     make(chan chan struct{}),
		utilTarget: utilTarget,
	}
	if config.LightBandwidthIn > 0 {
		ct.inSizeFactor = utilTarget / float64(config.LightBandwidthIn)
	}
	if config.LightBandwidthOut > 0 {
		ct.outSizeFactor = utilTarget / float64(config.LightBandwidthOut)
	}
	if makeCostStats {
		ct.stats = make(map[uint64][]uint64)
		for code := range reqAvgTimeCost {
			ct.stats[code] = make([]uint64, 10)
		}
	}
	ct.gfLoop()
	return ct
}
613448
func New(id TrackingID, rs RouteSpecification) *Cargo {
	itinerary := Itinerary{}
	history := HandlingHistory{make([]HandlingEvent, 0)}

	return &Cargo{
		TrackingID:         id,
		Origin:             rs.Origin,
		RouteSpecification: rs,
		Delivery:           DeriveDeliveryFrom(rs, itinerary, history),
	}
}
371632
func (obj *GCSObject) IsImportTarget(c context.Context, r *http.Request, bucketName string, kindNames []string) bool {
	if bucketName != "" && obj.Bucket != bucketName {
		log.Infof(c, "ds2bq: %s is unexpected bucket", obj.Bucket)
		return false
	}
	gcsHeader := NewGCSHeader(r)
	if gcsHeader.ResourceState != "exists" {
		log.Infof(c, "ds2bq: %s is unexpected state", gcsHeader.ResourceState)
		return false
	}
	if obj.ExtractKindName() == "" {
		log.Infof(c, "ds2bq: this is not backup file: %s", obj.Name)
		return false
	}
	if !obj.IsRequiredKind(kindNames) {
		log.Infof(c, "ds2bq: %s is not required kind", obj.ExtractKindName())
		return false
	}
	log.Infof(c, "ds2bq: %s should imports", obj.Name)
	return true
}
16457
func newNATSTransportWithLogger(id string, conn *nats.Conn, timeout time.Duration, logger *log.Logger) (*raft.NetworkTransport, error) {
	return createNATSTransport(id, conn, logger, timeout, func(stream raft.StreamLayer) *raft.NetworkTransport {
		return raft.NewNetworkTransportWithLogger(stream, 3, timeout, logger)
	})
}