// NewAPI creates the default untyped API
764289
func NewAPI(spec *loads.Document) *API {
	var an *analysis.Spec
	if spec != nil && spec.Spec() != nil {
		an = analysis.New(spec.Spec())
	}
	api := &API{
		spec:           spec,
		analyzer:       an,
		consumers:      make(map[string]runtime.Consumer, 10),
		producers:      make(map[string]runtime.Producer, 10),
		authenticators: make(map[string]runtime.Authenticator),
		operations:     make(map[string]map[string]runtime.OperationHandler),
		ServeError:     errors.ServeError,
		Models:         make(map[string]func() interface{}),
		formats:        strfmt.NewFormats(),
	}
	return api.WithJSONDefaults()
}
1356751
func NewAPIClient(cfg *Configuration) *APIClient {
	if cfg.HTTPClient == nil {
		cfg.HTTPClient = http.DefaultClient
	}

	c := &APIClient{}
	c.cfg = cfg
	c.common.client = c

	// API Services
	c.APIInfoApi = (*APIInfoApiService)(&c.common)
	c.AccountProvisioningApi = (*AccountProvisioningApiService)(&c.common)
	c.ApplicationSettingsApi = (*ApplicationSettingsApiService)(&c.common)
	c.CallHandlingSettingsApi = (*CallHandlingSettingsApiService)(&c.common)
	c.CallLogApi = (*CallLogApiService)(&c.common)
	c.CompanyContactsApi = (*CompanyContactsApiService)(&c.common)
	c.CompanySettingsApi = (*CompanySettingsApiService)(&c.common)
	c.GlipApi = (*GlipApiService)(&c.common)
	c.MeetingsApi = (*MeetingsApiService)(&c.common)
	c.MessagesApi = (*MessagesApiService)(&c.common)
	c.PhoneNumbersApi = (*PhoneNumbersApiService)(&c.common)
	c.PresenceApi = (*PresenceApiService)(&c.common)
	c.PushNotificationsApi = (*PushNotificationsApiService)(&c.common)
	c.RegionalSettingsApi = (*RegionalSettingsApiService)(&c.common)
	c.ReportingApi = (*ReportingApiService)(&c.common)
	c.RingOutApi = (*RingOutApiService)(&c.common)
	c.RolesAndPermissionsApi = (*RolesAndPermissionsApiService)(&c.common)
	c.SCIMApi = (*SCIMApiService)(&c.common)
	c.UserContactsApi = (*UserContactsApiService)(&c.common)
	c.UserSettingsApi = (*UserSettingsApiService)(&c.common)

	return c
}
207675
func NewAPI(s storage.Storage, logger log.Logger) api.DexServer {
	return dexAPI{
		s:      s,
		logger: logger,
	}
}
258075
func NewNFSAPI(client *Client) *NFSAPI {
	return &NFSAPI{
		&baseAPI{
			client: client,
			FuncGetResourceURL: func() string {
				return "appliance"
			},
			FuncBaseSearchCondition: func() *sacloud.Request {
				res := &sacloud.Request{}
				res.AddFilter("Class", "nfs")
				return res
			},
		},
	}
}
953765
func NewAPI(
	backend Backend,
	precheckBackend migration.PrecheckBackend,
	pool migration.Pool,
	resources facade.Resources,
	authorizer facade.Authorizer,
	presence facade.Presence,
) (*API, error) {
	if !authorizer.AuthController() {
		return nil, common.ErrPerm
	}
	return &API{
		backend:         backend,
		precheckBackend: precheckBackend,
		pool:            pool,
		authorizer:      authorizer,
		resources:       resources,
		presence:        presence,
	}, nil
}
554920
func NewInstanceMutaterAPI(st InstanceMutaterState,
	model ModelCache,
	resources facade.Resources,
	authorizer facade.Authorizer,
) (*InstanceMutaterAPI, error) {
	if !authorizer.AuthMachineAgent() && !authorizer.AuthController() {
		return nil, common.ErrPerm
	}

	getAuthFunc := common.AuthFuncForMachineAgent(authorizer)
	return &InstanceMutaterAPI{
		LifeGetter:  common.NewLifeGetter(st, getAuthFunc),
		st:          st,
		model:       model,
		resources:   resources,
		authorizer:  authorizer,
		getAuthFunc: getAuthFunc,
	}, nil
}
192211
func NewActionAPIV3(ctx facade.Context) (*APIv3, error) {
	api, err := newActionAPI(ctx.State(), ctx.Resources(), ctx.Auth())
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &APIv3{api}, nil
}
470532
func NewZoneAPI(client *Client) *ZoneAPI {
	return &ZoneAPI{
		&baseAPI{
			client: client,
			// FuncGetResourceURL
			FuncGetResourceURL: func() string {
				return "zone"
			},
		},
	}
}
821533
func NewApi(runningInKubernetes bool, metricSink *metricsink.MetricSink, historicalSource core.HistoricalSource, disableMetricExport bool) *Api {
	gkeMetrics := make(map[string]core.MetricDescriptor)
	gkeLabels := make(map[string]core.LabelDescriptor)
	for _, val := range core.StandardMetrics {
		gkeMetrics[val.Name] = val.MetricDescriptor
	}
	for _, val := range core.LabeledMetrics {
		gkeMetrics[val.Name] = val.MetricDescriptor
	}
	gkeMetrics[core.MetricCpuLimit.Name] = core.MetricCpuLimit.MetricDescriptor
	gkeMetrics[core.MetricMemoryLimit.Name] = core.MetricMemoryLimit.MetricDescriptor

	for _, val := range core.CommonLabels() {
		gkeLabels[val.Key] = val
	}
	for _, val := range core.ContainerLabels() {
		gkeLabels[val.Key] = val
	}
	for _, val := range core.PodLabels() {
		gkeLabels[val.Key] = val
	}

	return &Api{
		runningInKubernetes: runningInKubernetes,
		metricSink:          metricSink,
		historicalSource:    historicalSource,
		gkeMetrics:          gkeMetrics,
		gkeLabels:           gkeLabels,
		disabled:            disableMetricExport,
	}
}
685499
func NewBotAPI(token string, vtoken string, secret string) *BotAPI {
	return &BotAPI{
		Token:       token,
		AppSecret:   secret,
		VerifyToken: vtoken,
		Debug:       false,
		Client:      &http.Client{},
	}
}
686023
func (c *cloudImageMetadataCommandBase) NewImageMetadataAPI() (*imagemetadatamanager.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, err
	}
	return imagemetadatamanager.NewClient(root), nil
}
318095
func NewPublicNetAPI(net *p2p.Server, networkVersion uint64) *PublicNetAPI {
	return &PublicNetAPI{net, networkVersion}
}
186850
func NewAPIRouter(app *appContext, useRealIP, compressLarge bool) apiMux {
	// chi router
	mux := stackedMux(useRealIP)

	mux.Get("/", app.root)

	mux.Get("/status", app.status)
	mux.Get("/supply", app.coinSupply)

	compMiddleware := m.Next
	if compressLarge {
		log.Debug("Enabling compressed responses for large JSON payload endpoints.")
		compMiddleware = middleware.NewCompressor(3).Handler()
	}

	mux.Route("/block", func(r chi.Router) {
		r.Route("/best", func(rd chi.Router) {
			rd.Use(app.BlockIndexLatestCtx)
			rd.Get("/", app.getBlockSummary) // app.getLatestBlock
			rd.Get("/height", app.currentHeight)
			rd.Get("/hash", app.getBlockHash)
			rd.Route("/header", func(rt chi.Router) {
				rt.Get("/", app.getBlockHeader)
				rt.Get("/raw", app.getBlockHeaderRaw)
			})
			rd.Get("/raw", app.getBlockRaw)
			rd.Get("/size", app.getBlockSize)
			rd.Get("/subsidy", app.blockSubsidies)
			rd.With(compMiddleware).Get("/verbose", app.getBlockVerbose)
			rd.Get("/pos", app.getBlockStakeInfoExtendedByHeight)
			rd.Route("/tx", func(rt chi.Router) {
				rt.Get("/", app.getBlockTransactions)
				rt.Get("/count", app.getBlockTransactionsCount)
			})
		})

		r.Route("/hash/{blockhash}", func(rd chi.Router) {
			rd.Use(app.BlockHashPathAndIndexCtx)
			rd.Get("/", app.getBlockSummary)
			rd.Get("/height", app.getBlockHeight)
			rd.Route("/header", func(rt chi.Router) {
				rt.Get("/", app.getBlockHeader)
				rt.Get("/raw", app.getBlockHeaderRaw)
			})
			rd.Get("/raw", app.getBlockRaw)
			rd.Get("/size", app.getBlockSize)
			rd.Get("/subsidy", app.blockSubsidies)
			rd.With(compMiddleware).Get("/verbose", app.getBlockVerbose)
			rd.Get("/pos", app.getBlockStakeInfoExtendedByHash)
			rd.Route("/tx", func(rt chi.Router) {
				rt.Get("/", app.getBlockTransactions)
				rt.Get("/count", app.getBlockTransactionsCount)
			})
		})

		r.Route("/{idx}", func(rd chi.Router) {
			rd.Use(m.BlockIndexPathCtx)
			rd.Get("/", app.getBlockSummary)
			rd.Route("/header", func(rt chi.Router) {
				rt.Get("/", app.getBlockHeader)
				rt.Get("/raw", app.getBlockHeaderRaw)
			})
			rd.Get("/hash", app.getBlockHash)
			rd.Get("/raw", app.getBlockRaw)
			rd.Get("/size", app.getBlockSize)
			rd.Get("/subsidy", app.blockSubsidies)
			rd.With(compMiddleware).Get("/verbose", app.getBlockVerbose)
			rd.Get("/pos", app.getBlockStakeInfoExtendedByHeight)
			rd.Route("/tx", func(rt chi.Router) {
				rt.Get("/", app.getBlockTransactions)
				rt.Get("/count", app.getBlockTransactionsCount)
			})
		})

		r.Route("/range/{idx0}/{idx}", func(rd chi.Router) {
			rd.Use(m.BlockIndex0PathCtx, m.BlockIndexPathCtx)
			rd.Use(compMiddleware)
			rd.Get("/", app.getBlockRangeSummary)
			rd.Get("/size", app.getBlockRangeSize)
			rd.Route("/{step}", func(rs chi.Router) {
				rs.Use(m.BlockStepPathCtx)
				rs.Get("/", app.getBlockRangeSteppedSummary)
				rs.Get("/size", app.getBlockRangeSteppedSize)
			})
			// rd.Get("/header", app.getBlockHeader)
			// rd.Get("/pos", app.getBlockStakeInfoExtendedByHeight)
		})
	})

	mux.Route("/stake", func(r chi.Router) {
		r.Route("/vote", func(rd chi.Router) {
			rd.Use(app.StakeVersionLatestCtx)
			rd.Get("/info", app.getVoteInfo)
		})
		r.Route("/pool", func(rd chi.Router) {
			rd.With(app.BlockIndexLatestCtx).Get("/", app.getTicketPoolInfo)
			rd.With(app.BlockIndexLatestCtx).Get("/full", app.getTicketPool)
			rd.With(m.BlockIndexPathCtx).Get("/b/{idx}", app.getTicketPoolInfo)
			rd.With(m.BlockIndexOrHashPathCtx).Get("/b/{idxorhash}/full", app.getTicketPool)
			rd.With(m.BlockIndex0PathCtx, m.BlockIndexPathCtx).Get("/r/{idx0}/{idx}", app.getTicketPoolInfoRange)
		})
		r.Route("/diff", func(rd chi.Router) {
			rd.Get("/", app.getStakeDiffSummary)
			rd.Get("/current", app.getStakeDiffCurrent)
			rd.Get("/estimates", app.getStakeDiffEstimates)
			rd.With(m.BlockIndexPathCtx).Get("/b/{idx}", app.getStakeDiff)
			rd.With(m.BlockIndex0PathCtx, m.BlockIndexPathCtx).Get("/r/{idx0}/{idx}", app.getStakeDiffRange)
		})
		r.Get("/powerless", app.getPowerlessTickets)
	})

	mux.Route("/tx", func(r chi.Router) {
		r.Route("/", func(rt chi.Router) {
			rt.Route("/{txid}", func(rd chi.Router) {
				rd.Use(m.TransactionHashCtx)
				rd.Get("/", app.getTransaction)
				rd.Get("/trimmed", app.getDecodedTx)
				rd.Route("/out", func(ro chi.Router) {
					ro.Get("/", app.getTransactionOutputs)
					ro.With(m.TransactionIOIndexCtx).Get("/{txinoutindex}", app.getTransactionOutput)
				})
				rd.Route("/in", func(ri chi.Router) {
					ri.Get("/", app.getTransactionInputs)
					ri.With(m.TransactionIOIndexCtx).Get("/{txinoutindex}", app.getTransactionInput)
				})
				rd.Get("/vinfo", app.getTxVoteInfo)
				rd.Get("/tinfo", app.getTxTicketInfo)
			})
		})
		r.With(m.TransactionHashCtx).Get("/hex/{txid}", app.getTransactionHex)
		r.With(m.TransactionHashCtx).Get("/decoded/{txid}", app.getDecodedTx)
	})

	mux.Route("/txs", func(r chi.Router) {
		r.Use(middleware.AllowContentType("application/json"),
			m.ValidateTxnsPostCtx, m.PostTxnsCtx)
		r.Post("/", app.getTransactions)
		r.Post("/trimmed", app.getDecodedTransactions)
	})

	mux.Route("/address", func(r chi.Router) {
		r.Route("/{address}", func(rd chi.Router) {
			rd.Use(m.AddressPathCtx)
			rd.Get("/totals", app.addressTotals)
			rd.Get("/", app.getAddressTransactions)
			rd.With(m.ChartGroupingCtx).Get("/types/{chartgrouping}", app.getAddressTxTypesData)
			rd.With(m.ChartGroupingCtx).Get("/amountflow/{chartgrouping}", app.getAddressTxAmountFlowData)
			rd.With(compMiddleware).Get("/raw", app.getAddressTransactionsRaw)
			rd.Route("/count/{N}", func(ri chi.Router) {
				ri.Use(m.NPathCtx)
				ri.Get("/", app.getAddressTransactions)
				ri.With(compMiddleware).Get("/raw", app.getAddressTransactionsRaw)
				ri.Route("/skip/{M}", func(rj chi.Router) {
					rj.Use(m.MPathCtx)
					rj.Get("/", app.getAddressTransactions)
					rj.With(compMiddleware).Get("/raw", app.getAddressTransactionsRaw)
				})
			})
		})
	})

	// Returns agenda data like; description, name, lockedin activated and other
	// high level agenda details for all agendas.
	mux.Route("/agendas", func(r chi.Router) {
		r.Get("/", app.getAgendasData)
	})

	// Returns the charts data for the respective individual agendas.
	mux.Route("/agenda", func(r chi.Router) {
		r.With(m.AgendIdCtx).Get("/{agendaId}", app.getAgendaData)
	})

	mux.Route("/mempool", func(r chi.Router) {
		r.Get("/", http.NotFound /*app.getMempoolOverview*/)
		// ticket purchases
		r.Route("/sstx", func(rd chi.Router) {
			rd.Get("/", app.getSSTxSummary)
			rd.Get("/fees", app.getSSTxFees)
			rd.With(m.NPathCtx).Get("/fees/{N}", app.getSSTxFees)
			rd.Get("/details", app.getSSTxDetails)
			rd.With(m.NPathCtx).Get("/details/{N}", app.getSSTxDetails)
		})
	})

	mux.Route("/chart", func(r chi.Router) {
		// Return default chart data (ticket price)
		r.Route("/market/{token}", func(rd chi.Router) {
			rd.Use(m.ExchangeTokenContext)
			rd.With(m.StickWidthContext).Get("/candlestick/{bin}", app.getCandlestickChart)
			rd.Get("/depth", app.getDepthChart)
		})
		r.With(m.ChartTypeCtx).Get("/{charttype}", app.ChartTypeData)
	})

	mux.Route("/ticketpool", func(r chi.Router) {
		r.Get("/", app.getTicketPoolByDate)
		r.With(m.TicketPoolCtx).Get("/bydate/{tp}", app.getTicketPoolByDate)
		r.Get("/charts", app.getTicketPoolCharts)
	})

	mux.Route("/proposal", func(r chi.Router) {
		r.With(m.ProposalTokenCtx).Get("/{token}", app.getProposalChartData)
	})

	mux.Route("/exchanges", func(r chi.Router) {
		r.Get("/", app.getExchanges)
		r.Get("/codes", app.getCurrencyCodes)
	})

	mux.NotFound(func(w http.ResponseWriter, r *http.Request) {
		http.Error(w, r.URL.RequestURI()+" ain't no country I've ever heard of! (404)", http.StatusNotFound)
	})

	// if cfg.PrintAPIDirectory {
	// 	var buf bytes.Buffer
	// 	json.Indent(&buf, []byte(docgen.JSONRoutesDoc(mux)), "", "\t")
	// 	buf.WriteTo(os.Stdout)

	// 	fmt.Println(docgen.MarkdownRoutesDoc(mux, docgen.MarkdownOpts{
	// 		ProjectPath: "github.com/decred/dcrdata/v5",
	// 		Intro:       "dcrdata HTTP router directory",
	// 	}))
	// 	return
	// }

	// mux.HandleFunc("/directory", APIDirectory)
	// mux.With(apiDocs(mux)).HandleFunc("/directory", APIDirectory)

	var listRoutePatterns func(routes []chi.Route) []string
	listRoutePatterns = func(routes []chi.Route) []string {
		patterns := []string{}
		for _, rt := range routes {
			patterns = append(patterns, strings.Replace(rt.Pattern, "/*", "", -1))
			if rt.SubRoutes == nil {
				continue
			}
			for _, pt := range listRoutePatterns(rt.SubRoutes.Routes()) {
				patterns = append(patterns, strings.Replace(rt.Pattern+pt, "/*", "", -1))
			}
		}
		return patterns
	}

	mux.HandleFunc("/list", app.writeJSONHandlerFunc(listRoutePatterns(mux.Routes())))

	return apiMux{mux}
}
343580
func NewAPI(
	apiCaller base.APICaller,
	claimant names.MachineTag,
	entity names.Tag,
) (*API, error) {
	if !names.IsValidMachine(claimant.Id()) {
		return nil, errors.NotValidf("claimant tag")
	}
	switch entity.(type) {
	case names.ModelTag:
	case names.ControllerTag:
	case nil:
		return nil, errors.New("nil entity supplied")
	default:
		return nil, errors.Errorf(
			"invalid entity kind %q for singular API", entity.Kind(),
		)
	}
	facadeCaller := base.NewFacadeCaller(apiCaller, "Singular")
	return &API{
		facadeCaller: facadeCaller,
		claimant:     claimant,
		entity:       entity,
	}, nil
}
1252343
func NewIPv6NetAPI(client *Client) *IPv6NetAPI {
	return &IPv6NetAPI{
		&baseAPI{
			client: client,
			FuncGetResourceURL: func() string {
				return "ipv6net"
			},
		},
	}
}
760633
func (c *diffCommand) getAPI() (DiffCommandAPI, error) {
	if c.api != nil {
		return c.api, nil
	}
	api, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Annotate(err, "opening API connection")
	}
	client := modelgeneration.NewClient(api)
	return client, nil
}
1368665
func HostApi(apiType HostApiType) (*HostApiInfo, error) {
	hosts, err := HostApis()
	if err != nil {
		return nil, err
	}
	i := C.Pa_HostApiTypeIdToHostApiIndex(C.PaHostApiTypeId(apiType))
	if i < 0 {
		return nil, newError(C.PaError(i))
	}
	return hosts[i], nil
}