本文整理匯總了Golang中github.com/tedsuo/ifrit/http_server.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: constructApiServer
func constructApiServer(cfg config.Config, database db.DB, statsdClient statsd.Statter, stopChan chan struct{}, logger lager.Logger) ifrit.Runner {
var token authentication.Token
if *devMode {
token = authentication.NullToken{}
} else {
token = authentication.NewAccessToken(cfg.UAAPublicKey)
err := token.CheckPublicToken()
if err != nil {
logger.Error("failed to check public token", err)
os.Exit(1)
}
}
validator := handlers.NewValidator()
routesHandler := handlers.NewRoutesHandler(token, *maxTTL, validator, database, logger)
eventStreamHandler := handlers.NewEventStreamHandler(token, database, logger, statsdClient, stopChan)
actions := rata.Handlers{
"Upsert": route(routesHandler.Upsert),
"Delete": route(routesHandler.Delete),
"List": route(routesHandler.List),
"EventStream": route(eventStreamHandler.EventStream),
}
handler, err := rata.NewRouter(routing_api.Routes, actions)
if err != nil {
logger.Error("failed to create router", err)
os.Exit(1)
}
handler = handlers.LogWrap(handler, logger)
return http_server.New(":"+strconv.Itoa(*port), handler)
}
示例2: Run
func (f *FakeCC) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
err := http_server.New(f.address, f).Run(signals, ready)
f.Reset()
return err
}
示例3: initializeServer
func initializeServer(
bbsClient bbs.Client,
executorClient executor.Client,
evacuatable evacuation_context.Evacuatable,
evacuationReporter evacuation_context.EvacuationReporter,
logger lager.Logger,
stackMap rep.StackPathMap,
supportedProviders []string,
) (ifrit.Runner, string) {
lrpStopper := initializeLRPStopper(*cellID, executorClient, logger)
auctionCellRep := auction_cell_rep.New(*cellID, stackMap, supportedProviders, *zone, generateGuid, executorClient, evacuationReporter, logger)
handlers := handlers.New(auctionCellRep, lrpStopper, executorClient, evacuatable, logger)
router, err := rata.NewRouter(rep.Routes, handlers)
if err != nil {
logger.Fatal("failed-to-construct-router", err)
}
ip, err := localip.LocalIP()
if err != nil {
logger.Fatal("failed-to-fetch-ip", err)
}
port := strings.Split(*listenAddr, ":")[1]
address := fmt.Sprintf("http://%s:%s", ip, port)
return http_server.New(*listenAddr, router), address
}
示例4: MonitorJobFailures
func (w *windowsJobSupervisor) MonitorJobFailures(handler JobFailureHandler) error {
hl := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
if s.stateIs(stateDisabled) {
return
}
var event windowsServiceEvent
err := json.NewDecoder(r.Body).Decode(&event)
if err != nil {
s.logger.Error(s.logTag, "MonitorJobFailures received unknown request: %s", err)
return
}
handler(boshalert.MonitAlert{
Action: "Start",
Date: time.Now().Format(time.RFC1123Z),
Event: event.Event,
ID: event.ProcessName,
Service: event.ProcessName,
Description: fmt.Sprintf("exited with code %d", event.ExitCode),
})
})
server := http_server.New(fmt.Sprintf("localhost:%d", s.jobFailuresServerPort), hl)
process := ifrit.Invoke(server)
for {
select {
case <-s.cancelServer:
process.Signal(os.Kill)
case err := <-process.Wait():
if err != nil {
return bosherr.WrapError(err, "Listen for HTTP")
}
return nil
}
}
}
示例5: initializeServer
func initializeServer(logger lager.Logger, uploaderConfig config.UploaderConfig) ifrit.Runner {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: ccUploadDialTimeout,
KeepAlive: ccUploadKeepAlive,
}).Dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: uploaderConfig.SkipCertVerify,
},
TLSHandshakeTimeout: ccUploadTLSHandshakeTimeout,
}
pollerHttpClient := cfhttp.NewClient()
pollerHttpClient.Transport = transport
uploader := ccclient.NewUploader(logger, &http.Client{Transport: transport})
poller := ccclient.NewPoller(logger, pollerHttpClient, time.Duration(uploaderConfig.CCJobPollingInterval))
ccUploaderHandler, err := handlers.New(uploader, poller, logger)
if err != nil {
logger.Error("router-building-failed", err)
os.Exit(1)
}
return http_server.New(uploaderConfig.ListenAddress, ccUploaderHandler)
}
示例6: ServeAPI
func ServeAPI(l logger.Logger, conf *config.Config) {
store := connectToStore(l, conf)
apiHandler, err := handlers.New(l, store, buildTimeProvider(l))
if err != nil {
l.Error("initialize-handler.failed", err)
panic(err)
}
handler := handlers.BasicAuthWrap(apiHandler, conf.APIServerUsername, conf.APIServerPassword)
listenAddr := fmt.Sprintf("%s:%d", conf.APIServerAddress, conf.APIServerPort)
members := grouper.Members{
{"api", http_server.New(listenAddr, handler)},
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
l.Info("started")
l.Info(listenAddr)
err = <-monitor.Wait()
if err != nil {
l.Error("exited", err)
os.Exit(1)
}
l.Info("exited")
os.Exit(0)
}
示例7: initializeServer
func initializeServer(logger lager.Logger) ifrit.Runner {
if *staticDirectory == "" {
logger.Fatal("static-directory-missing", nil)
}
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: ccUploadDialTimeout,
KeepAlive: ccUploadKeepAlive,
}).Dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: *skipCertVerify,
},
TLSHandshakeTimeout: ccUploadTLSHandshakeTimeout,
}
pollerHttpClient := cf_http.NewClient()
pollerHttpClient.Transport = transport
fileServerHandler, err := handlers.New(*staticDirectory, logger)
if err != nil {
logger.Error("router-building-failed", err)
os.Exit(1)
}
return http_server.New(*serverAddress, fileServerHandler)
}
示例8: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
logger, reconfigurableSink := cf_lager.New("tps-listener")
initializeDropsonde(logger)
noaaClient := noaa.NewConsumer(*trafficControllerURL, &tls.Config{InsecureSkipVerify: *skipSSLVerification}, nil)
defer noaaClient.Close()
apiHandler := initializeHandler(logger, noaaClient, *maxInFlightRequests, initializeBBSClient(logger))
members := grouper.Members{
{"api", http_server.New(*listenAddr, apiHandler)},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err := <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例9: StartDebugServer
func StartDebugServer(address string, sink *lager.ReconfigurableSink, metrics Metrics) (ifrit.Process, error) {
expvar.Publish("numCPUS", expvar.Func(func() interface{} {
return metrics.NumCPU()
}))
expvar.Publish("numGoRoutines", expvar.Func(func() interface{} {
return metrics.NumGoroutine()
}))
expvar.Publish("loopDevices", expvar.Func(func() interface{} {
return metrics.LoopDevices()
}))
expvar.Publish("backingStores", expvar.Func(func() interface{} {
return metrics.BackingStores()
}))
expvar.Publish("depotDirs", expvar.Func(func() interface{} {
return metrics.DepotDirs()
}))
server := http_server.New(address, handler(sink))
p := ifrit.Invoke(server)
select {
case <-p.Ready():
case err := <-p.Wait():
return nil, err
}
return p, nil
}
示例10: main
func main() {
logger := configureLogger()
flag.Parse()
validateFlags(logger)
router := configureRouter(logger)
var server ifrit.Runner
server = http_server.New(*listenAddress, router)
members := grouper.Members{
{"server", server},
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err := <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例11: main
func main() {
logger := lager.NewLogger("checkin")
logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
var opts Opts
_, err := flags.Parse(&opts)
if err != nil {
logger.Error("parsing-flags", err)
os.Exit(1)
}
// ts := oauth2.StaticTokenSource(
// &oauth2.Token{AccessToken: opts.GitHubAccessToken},
// )
// tc := oauth2.NewClient(oauth2.NoContext, ts)
// githubClient := github.NewClient(tc)
// checker := build.NewConcourseChecker()
// checker = build.NewStatusReporter(checker, githubClient.Repositories)
dbConn, err := migration.Open(opts.DBDriver, opts.DBURL, migrations.Migrations)
if err != nil {
logger.Error("failed-to-run-migrations", err)
os.Exit(1)
}
sqlDB := db.NewSQL(logger.Session("db"), dbConn)
enqueuer := build.NewEnqueuer(sqlDB)
apiServer := api.NewServer(opts.GitHubSecret, enqueuer)
members := []grouper.Member{
{
"api",
http_server.New(
opts.Addr,
apiServer,
),
},
}
group := grouper.NewParallel(os.Interrupt, members)
running := ifrit.Invoke(sigmon.New(group))
logger.Info("listening", lager.Data{
"api": opts.Addr,
})
err = <-running.Wait()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
示例12: main
func main() {
flag.Parse()
logger := lager.NewLogger("lattice-app")
if quiet {
logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
} else {
logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
}
ports := getServerPorts()
logger.Info("lattice-app.starting", lager.Data{"ports": ports})
handler, err := rata.NewRouter(routes.Routes, handlers.New(logger))
if err != nil {
logger.Fatal("router.creation.failed", err)
}
index, err := helpers.FetchIndex()
appName := fetchAppName()
go func() {
t := time.NewTicker(time.Second)
for {
<-t.C
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to fetch index: %s\n", err.Error())
} else {
fmt.Println(fmt.Sprintf("%s. Says %s. on index: %d", appName, message, index))
}
}
}()
wg := sync.WaitGroup{}
for _, port := range ports {
wg.Add(1)
go func(wg *sync.WaitGroup, port string) {
defer wg.Done()
server := ifrit.Envoke(http_server.New(":"+port, handler))
logger.Info("lattice-app.up", lager.Data{"port": port})
err = <-server.Wait()
if err != nil {
logger.Error("shutting down server", err, lager.Data{"server port": port})
}
logger.Info("shutting down server", lager.Data{"server port": port})
}(&wg, port)
}
wg.Wait()
logger.Info("shutting latice app")
}
示例13: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
lifecycles := flags.LifecycleMap{}
flag.Var(&lifecycles, "lifecycle", "app lifecycle binary bundle mapping (lifecycle[/stack]:bundle-filepath-in-fileserver)")
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("nsync-listener")
initializeDropsonde(logger)
recipeBuilderConfig := recipebuilder.Config{
Lifecycles: lifecycles,
FileServerURL: *fileServerURL,
KeyFactory: keys.RSAKeyPairFactory,
}
recipeBuilders := map[string]recipebuilder.RecipeBuilder{
"buildpack": recipebuilder.NewBuildpackRecipeBuilder(logger, recipeBuilderConfig),
"docker": recipebuilder.NewDockerRecipeBuilder(logger, recipeBuilderConfig),
}
handler := handlers.New(logger, initializeBBSClient(logger), recipeBuilders)
members := grouper.Members{
{"server", http_server.New(*listenAddress, handler)},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err := <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例14: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Var(
&insecureDockerRegistries,
"insecureDockerRegistry",
"Docker registry to allow connecting to even if not secure. (Can be specified multiple times to allow insecure connection to multiple repositories)",
)
lifecycles := flags.LifecycleMap{}
flag.Var(&lifecycles, "lifecycle", "app lifecycle binary bundle mapping (lifecycle[/stack]:bundle-filepath-in-fileserver)")
flag.Parse()
logger, reconfigurableSink := cf_lager.New("stager")
initializeDropsonde(logger)
ccClient := cc_client.NewCcClient(*ccBaseURL, *ccUsername, *ccPassword, *skipCertVerify)
backends := initializeBackends(logger, lifecycles)
handler := handlers.New(logger, ccClient, initializeBBSClient(logger), backends, clock.NewClock())
members := grouper.Members{
{"server", http_server.New(*listenAddress, handler)},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
logger.Info("starting")
group := grouper.NewOrdered(os.Interrupt, members)
process := ifrit.Invoke(sigmon.New(group))
logger.Info("Listening for staging requests!")
err := <-process.Wait()
if err != nil {
logger.Fatal("Stager exited with error", err)
}
logger.Info("stopped")
}
示例15: constructApiServer
func constructApiServer(cfg config.Config, database db.DB, statsdClient statsd.Statter, stopChan chan struct{}, logger lager.Logger) ifrit.Runner {
var tokenValidator authentication.TokenValidator
if *devMode {
tokenValidator = authentication.NullTokenValidator{}
} else {
uaaKeyFetcher := authentication.NewUaaKeyFetcher(logger, cfg.UAAEndpoint+"/token_key")
uaaPublicKey, err := uaaKeyFetcher.FetchKey()
if err != nil {
logger.Error("Failed to get verification key from UAA", err)
os.Exit(1)
}
tokenValidator = authentication.NewAccessTokenValidator(logger, uaaPublicKey, uaaKeyFetcher)
err = tokenValidator.CheckPublicToken()
if err != nil {
logger.Error("Failed to check public token", err)
os.Exit(1)
}
}
validator := handlers.NewValidator()
routesHandler := handlers.NewRoutesHandler(tokenValidator, *maxTTL, validator, database, logger)
eventStreamHandler := handlers.NewEventStreamHandler(tokenValidator, database, logger, statsdClient, stopChan)
routeGroupsHandler := handlers.NewRouteGroupsHandler(tokenValidator, logger)
tcpMappingsHandler := handlers.NewTcpRouteMappingsHandler(tokenValidator, validator, database, logger)
actions := rata.Handlers{
routing_api.UpsertRoute: route(routesHandler.Upsert),
routing_api.DeleteRoute: route(routesHandler.Delete),
routing_api.ListRoute: route(routesHandler.List),
routing_api.EventStreamRoute: route(eventStreamHandler.EventStream),
routing_api.ListRouterGroups: route(routeGroupsHandler.ListRouterGroups),
routing_api.UpsertTcpRouteMapping: route(tcpMappingsHandler.Upsert),
routing_api.DeleteTcpRouteMapping: route(tcpMappingsHandler.Delete),
routing_api.ListTcpRouteMapping: route(tcpMappingsHandler.List),
routing_api.EventStreamTcpRoute: route(eventStreamHandler.TcpEventStream),
}
handler, err := rata.NewRouter(routing_api.Routes, actions)
if err != nil {
logger.Error("failed to create router", err)
os.Exit(1)
}
handler = handlers.LogWrap(handler, logger)
return http_server.New(":"+strconv.Itoa(int(*port)), handler)
}