本文整理匯總了Golang中github.com/flynn/flynn/pkg/status.AddHandler函數的典型用法代碼示例。如果您正苦於以下問題:Golang AddHandler函數的具體用法?Golang AddHandler怎麽用?Golang AddHandler使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AddHandler函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
// main is a modified version of the registry main function:
// https://github.com/docker/distribution/blob/6ba799b/cmd/registry/main.go
func main() {
logrus.SetLevel(logrus.InfoLevel)
ctx := context.Background()
ctx = context.WithValue(ctx, "version", version.String())
ctx = context.WithLogger(ctx, context.GetLogger(ctx, "version"))
client, err := controller.NewClient("", os.Getenv("CONTROLLER_KEY"))
if err != nil {
context.GetLogger(ctx).Fatalln(err)
}
release, err := client.GetRelease(os.Getenv("FLYNN_RELEASE_ID"))
if err != nil {
context.GetLogger(ctx).Fatalln(err)
}
artifact, err := client.GetArtifact(release.ArtifactIDs[0])
if err != nil {
context.GetLogger(ctx).Fatalln(err)
}
authKey := os.Getenv("AUTH_KEY")
middleware.Register("flynn", repositoryMiddleware(client, artifact, authKey))
config := configuration.Configuration{
Version: configuration.CurrentVersion,
Storage: configuration.Storage{
blobstore.DriverName: configuration.Parameters{},
"delete": configuration.Parameters{"enabled": true},
},
Middleware: map[string][]configuration.Middleware{
"repository": {
{Name: "flynn"},
},
},
Auth: configuration.Auth{
"flynn": configuration.Parameters{
"auth_key": authKey,
},
},
}
config.HTTP.Secret = os.Getenv("REGISTRY_HTTP_SECRET")
status.AddHandler(status.HealthyHandler)
app := handlers.NewApp(ctx, config)
http.Handle("/", app)
addr := ":" + os.Getenv("PORT")
context.GetLogger(app).Infof("listening on %s", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
context.GetLogger(app).Fatalln(err)
}
}
示例2: startHTTPServer
func (s *Scheduler) startHTTPServer(port string) {
log := logger.New("fn", "startHTTPServer")
status.AddHandler(status.HealthyHandler)
addr := ":" + port
log.Info("serving HTTP requests", "addr", addr)
err := http.ListenAndServe(":"+port, nil)
if err != nil {
log.Error("error serving HTTP requests", "err", err)
s.Stop()
}
}
示例3: main
func main() {
log := logger.New("fn", "main")
log.Info("creating controller client")
client, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
if err != nil {
log.Error("error creating controller client", "err", err)
shutdown.Fatal(err)
}
log.Info("connecting to postgres")
db := postgres.Wait(nil, schema.PrepareStatements)
shutdown.BeforeExit(func() { db.Close() })
go func() {
status.AddHandler(func() status.Status {
_, err := db.ConnPool.Exec("ping")
if err != nil {
return status.Unhealthy
}
return status.Healthy
})
addr := ":" + os.Getenv("PORT")
hb, err := discoverd.AddServiceAndRegister("controller-worker", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
shutdown.Fatal(http.ListenAndServe(addr, nil))
}()
workers := que.NewWorkerPool(
que.NewClient(db.ConnPool),
que.WorkMap{
"deployment": deployment.JobHandler(db, client, logger),
"app_deletion": app_deletion.JobHandler(db, client, logger),
"domain_migration": domain_migration.JobHandler(db, client, logger),
"release_cleanup": release_cleanup.JobHandler(db, client, logger),
"app_garbage_collection": app_garbage_collection.JobHandler(db, client, logger),
},
workerCount,
)
workers.Interval = 5 * time.Second
log.Info("starting workers", "count", workerCount, "interval", workers.Interval)
workers.Start()
shutdown.BeforeExit(func() { workers.Shutdown() })
select {} // block and keep running
}
示例4: httpServer
func httpServer(sn *subnet.SubnetManager, publicIP, port string) error {
overlayListener, err := net.Listen("tcp", net.JoinHostPort(sn.Lease().Network.IP.String(), port))
if err != nil {
return err
}
publicListener, err := net.Listen("tcp", net.JoinHostPort(publicIP, port))
http.HandleFunc("/ping", func(http.ResponseWriter, *http.Request) {})
status.AddHandler(status.SimpleHandler(func() error {
return pingLeases(sn.Leases())
}))
go http.Serve(overlayListener, nil)
go http.Serve(publicListener, nil)
return nil
}
示例5: startHTTPServer
func (s *Scheduler) startHTTPServer(port string) {
log := s.logger.New("fn", "startHTTPServer")
http.HandleFunc("/debug/state", func(w http.ResponseWriter, _ *http.Request) {
json.NewEncoder(w).Encode(s.InternalState())
})
status.AddHandler(status.HealthyHandler)
addr := ":" + port
log.Info("serving HTTP requests", "addr", addr)
err := http.ListenAndServe(":"+port, nil)
if err != nil {
log.Error("error serving HTTP requests", "err", err)
s.Stop()
}
}
示例6: main
func main() {
defer shutdown.Exit()
flag.Parse()
addr := os.Getenv("PORT")
if addr == "" {
addr = *listenPort
}
addr = ":" + addr
var fs Filesystem
var storageDesc string
if *storageDir != "" {
fs = NewOSFilesystem(*storageDir)
storageDesc = *storageDir
} else {
db, err := postgres.Open("", "")
if err != nil {
shutdown.Fatal(err)
}
fs, err = NewPostgresFilesystem(db.DB)
if err != nil {
shutdown.Fatal(err)
}
storageDesc = "Postgres"
}
if *serviceDiscovery {
hb, err := discoverd.AddServiceAndRegister("blobstore", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
}
log.Println("Blobstore serving files on " + addr + " from " + storageDesc)
http.Handle("/", handler(fs))
status.AddHandler(fs.Status)
shutdown.Fatal(http.ListenAndServe(addr, nil))
}
示例7: startHTTPServer
func startHTTPServer() {
status.AddHandler(status.HealthyHandler)
shutdown.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
}
示例8: main
func main() {
log := logger.New("fn", "main")
log.Info("creating controller client")
client, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
if err != nil {
log.Error("error creating controller client", "err", err)
shutdown.Fatal()
}
log.Info("connecting to postgres")
db := postgres.Wait("", "")
log.Info("creating postgres connection pool")
pgxpool, err := pgx.NewConnPool(pgx.ConnPoolConfig{
ConnConfig: pgx.ConnConfig{
Host: os.Getenv("PGHOST"),
User: os.Getenv("PGUSER"),
Password: os.Getenv("PGPASSWORD"),
Database: os.Getenv("PGDATABASE"),
},
AfterConnect: que.PrepareStatements,
MaxConnections: workerCount,
})
if err != nil {
log.Error("error creating postgres connection pool", "err", err)
shutdown.Fatal()
}
shutdown.BeforeExit(func() { pgxpool.Close() })
go func() {
status.AddHandler(func() status.Status {
_, err := pgxpool.Exec("SELECT 1")
if err != nil {
return status.Unhealthy
}
return status.Healthy
})
addr := ":" + os.Getenv("PORT")
hb, err := discoverd.AddServiceAndRegister("flynn-controller-worker", addr)
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
shutdown.Fatal(http.ListenAndServe(addr, nil))
}()
workers := que.NewWorkerPool(
que.NewClient(pgxpool),
que.WorkMap{
"deployment": deployment.JobHandler(db, client, logger),
"app_deletion": app_deletion.JobHandler(db, client, logger),
},
workerCount,
)
workers.Interval = 5 * time.Second
log.Info("starting workers", "count", workerCount, "interval", workers.Interval)
workers.Start()
shutdown.BeforeExit(func() { workers.Shutdown() })
select {} // block and keep running
}