本文整理匯總了Golang中github.com/cloudfoundry-incubator/cf_http.Initialize函數的典型用法代碼示例。如果您正苦於以下問題:Golang Initialize函數的具體用法?Golang Initialize怎麽用?Golang Initialize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Initialize函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("auctioneer")
initializeDropsonde(logger)
if err := validateBBSAddress(); err != nil {
logger.Fatal("invalid-bbs-address", err)
}
consulClient, err := consuladapter.NewClientFromUrl(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
port, err := strconv.Atoi(strings.Split(*listenAddr, ":")[1])
if err != nil {
logger.Fatal("invalid-port", err)
}
clock := clock.NewClock()
auctioneerServiceClient := auctioneer.NewServiceClient(consulClient, clock)
auctionRunner := initializeAuctionRunner(logger, *cellStateTimeout,
initializeBBSClient(logger), *startingContainerWeight)
auctionServer := initializeAuctionServer(logger, auctionRunner)
lockMaintainer := initializeLockMaintainer(logger, auctioneerServiceClient, port)
registrationRunner := initializeRegistrationRunner(logger, consulClient, clock, port)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"auction-runner", auctionRunner},
{"auction-server", auctionServer},
{"registration-runner", registrationRunner},
}
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")
}
示例2: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("file-server")
initializeDropsonde(logger)
members := grouper.Members{
{"file server", initializeServer(logger)},
}
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("ready")
err := <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例3: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("auctioneer")
initializeDropsonde(logger)
if err := validateBBSAddress(); err != nil {
logger.Fatal("invalid-bbs-address", err)
}
client, err := consuladapter.NewClient(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
sessionMgr := consuladapter.NewSessionManager(client)
consulSession, err := consuladapter.NewSession("auctioneer", *lockTTL, client, sessionMgr)
if err != nil {
logger.Fatal("consul-session-failed", err)
}
clock := clock.NewClock()
bbsServiceClient := bbs.NewServiceClient(consulSession, clock)
auctioneerServiceClient := auctioneer.NewServiceClient(consulSession, clock)
auctionRunner := initializeAuctionRunner(logger, *cellStateTimeout, initializeBBSClient(logger), bbsServiceClient)
auctionServer := initializeAuctionServer(logger, auctionRunner)
lockMaintainer := initializeLockMaintainer(logger, auctioneerServiceClient)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"auction-runner", auctionRunner},
{"auction-server", auctionServer},
}
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")
}
示例4: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New(*sessionName)
natsClient := diegonats.NewClient()
clock := clock.NewClock()
syncer := syncer.NewSyncer(clock, *syncInterval, natsClient, logger)
initializeDropsonde(logger)
natsClientRunner := diegonats.NewClientRunner(*natsAddresses, *natsUsername, *natsPassword, logger, natsClient)
table := initializeRoutingTable()
emitter := initializeNatsEmitter(natsClient, logger)
watcher := ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
return watcher.NewWatcher(initializeBBSClient(logger), clock, table, emitter, syncer.Events(), logger).Run(signals, ready)
})
syncRunner := ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
return syncer.Run(signals, ready)
})
lockMaintainer := initializeLockMaintainer(logger, *consulCluster, *sessionName, *lockTTL, *lockRetryInterval, clock)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"nats-client", natsClientRunner},
{"watcher", watcher},
{"syncer", syncRunner},
}
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")
}
示例5: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("ssh-proxy")
initializeDropsonde(logger)
proxyConfig, err := configureProxy(logger)
if err != nil {
logger.Error("configure-failed", err)
os.Exit(1)
}
sshProxy := proxy.New(logger, proxyConfig)
server := server.NewServer(logger, *address, sshProxy)
consulClient, err := consuladapter.NewClientFromUrl(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
registrationRunner := initializeRegistrationRunner(logger, consulClient, *address, clock.NewClock())
members := grouper.Members{
{"ssh-proxy", server},
{"registration-runner", registrationRunner},
}
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")
os.Exit(0)
}
示例6: 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")
}
示例7: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("ssh-proxy")
err := dropsonde.Initialize(dropsondeDestination, dropsondeOrigin)
if err != nil {
logger.Error("failed-to-initialize-dropsonde", err)
}
proxyConfig, err := configureProxy(logger)
if err != nil {
logger.Error("configure-failed", err)
os.Exit(1)
}
sshProxy := proxy.New(logger, proxyConfig)
server := server.NewServer(logger, *address, sshProxy)
members := grouper.Members{
{"ssh-proxy", server},
}
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")
os.Exit(0)
}
示例8:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
)
var _ = Describe("TaskWorker", func() {
var (
fakeServer *ghttp.Server
logger *lagertest.TestLogger
timeout time.Duration
)
BeforeEach(func() {
timeout = 1 * time.Second
cf_http.Initialize(timeout)
fakeServer = ghttp.NewServer()
logger = lagertest.NewTestLogger("test")
logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.INFO))
})
AfterEach(func() {
fakeServer.Close()
})
Describe("HandleCompletedTask", func() {
var (
callbackURL string
taskDB *dbfakes.FakeTaskDB
statusCodes chan int
示例9: 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)
consulClient, err := consuladapter.NewClientFromUrl(*consulCluster)
if err != nil {
logger.Fatal("new-consul-client-failed", err)
}
_, portString, err := net.SplitHostPort(*listenAddress)
if err != nil {
logger.Fatal("failed-invalid-listen-address", err)
}
portNum, err := net.LookupPort("tcp", portString)
if err != nil {
logger.Fatal("failed-invalid-listen-port", err)
}
clock := clock.NewClock()
registrationRunner := initializeRegistrationRunner(logger, consulClient, portNum, clock)
members := grouper.Members{
{"server", http_server.New(*listenAddress, handler)},
{"registration-runner", registrationRunner},
}
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")
}
示例10: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
etcdFlags := etcdstoreadapter.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("receptor")
logger.Info("starting")
initializeDropsonde(logger)
etcdOptions, err := etcdFlags.Validate()
if err != nil {
logger.Fatal("etcd-validation-failed", err)
}
if err := validateNatsArguments(); err != nil {
logger.Error("invalid-nats-flags", err)
os.Exit(1)
}
bbs := initializeReceptorBBS(etcdOptions, logger)
hub := event.NewHub()
handler := handlers.New(bbs, hub, logger, *username, *password, *corsEnabled)
worker, enqueue := task_handler.NewTaskWorkerPool(bbs, logger)
taskHandler := task_handler.New(enqueue, logger)
lrpChangeWatcher := watcher.NewWatcher(
bbs,
hub,
clock.NewClock(),
bbsWatchRetryWaitDuration,
logger,
)
members := grouper.Members{
{"lrp-change-watcher", lrpChangeWatcher},
{"server", http_server.New(*serverAddress, handler)},
{"worker", worker},
{"task-complete-handler", http_server.New(*taskHandlerAddress, taskHandler)},
{"hub-closer", closeHub(logger.Session("hub-closer"), hub)},
}
if *registerWithRouter {
registration := initializeServerRegistration(logger)
natsClient := diegonats.NewClient()
members = append(members, grouper.Member{
Name: "background-heartbeat",
Runner: natbeat.NewBackgroundHeartbeat(natsClient, *natsAddresses, *natsUsername, *natsPassword, logger, registration),
})
}
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")
}
示例11: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
etcdFlags := AddETCDFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("bbs")
logger.Info("starting")
initializeDropsonde(logger)
etcdOptions, err := etcdFlags.Validate()
if err != nil {
logger.Fatal("etcd-validation-failed", err)
}
var etcdClient *etcdclient.Client
if etcdOptions.IsSSL {
etcdClient, err = etcdclient.NewTLSClient(etcdOptions.ClusterUrls, etcdOptions.CertFile, etcdOptions.KeyFile, etcdOptions.CAFile)
if err != nil {
logger.Fatal("failed-to-construct-etcd-tls-client", err)
}
} else {
etcdClient = etcdclient.NewClient(etcdOptions.ClusterUrls)
}
etcdClient.SetConsistency(etcdclient.STRONG_CONSISTENCY)
err = validateAuctioneerFlag()
if err != nil {
logger.Fatal("auctioneer-address-validation-failed", err)
}
auctioneerClient := auctionhandlers.NewClient(*auctioneerAddress)
consulSession := initializeConsul(logger)
consulDB := consuldb.NewConsul(consulSession)
cellClient := cellhandlers.NewClient()
db := etcddb.NewETCD(etcdClient, auctioneerClient, cellClient, consulDB, clock.NewClock())
hub := events.NewHub()
watcher := watcher.NewWatcher(
logger,
db,
hub,
clock.NewClock(),
bbsWatchRetryWaitDuration,
)
handler := handlers.New(logger, db, hub)
members := grouper.Members{
{"watcher", watcher},
{"server", http_server.New(*serverAddress, handler)},
{"hub-closer", closeHub(logger.Session("hub-closer"), hub)},
}
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")
}
示例12: configure
func configure(logger lager.Logger) (*ssh.ServerConfig, error) {
cf_http.Initialize(*communicationTimeout)
if *diegoAPIURL == "" {
err := errors.New("diegoAPIURL is required")
logger.Fatal("diego-api-url-required", err)
}
url, err := url.Parse(*diegoAPIURL)
if err != nil {
logger.Fatal("failed-to-parse-diego-api-url", err)
}
_, err = url.Parse(*ccAPIURL)
if *ccAPIURL != "" && err != nil {
logger.Fatal("failed-to-parse-cc-api-url", err)
}
var diegoCreds string
if url.User != nil {
diegoCreds = url.User.String()
}
receptorClient := receptor.NewClient(*diegoAPIURL)
authenticatorMap := map[string]authenticators.PasswordAuthenticator{}
if *enableDiegoAuth {
diegoAuthenticator := authenticators.NewDiegoProxyAuthenticator(logger, receptorClient, []byte(diegoCreds))
authenticatorMap[diegoAuthenticator.Realm()] = diegoAuthenticator
}
if *ccAPIURL != "" && *enableCFAuth {
ccClient := cf_http.NewClient()
cfAuthenticator := authenticators.NewCFAuthenticator(logger, ccClient, *ccAPIURL, receptorClient)
authenticatorMap[cfAuthenticator.Realm()] = cfAuthenticator
}
authenticator := authenticators.NewCompositeAuthenticator(authenticatorMap)
sshConfig := &ssh.ServerConfig{
PasswordCallback: authenticator.Authenticate,
AuthLogCallback: func(cmd ssh.ConnMetadata, method string, err error) {
logger.Error("authentication-failed", err, lager.Data{"user": cmd.User()})
},
}
if *hostKey == "" {
err := errors.New("hostKey is required")
logger.Fatal("host-key-required", err)
}
key, err := parsePrivateKey(logger, *hostKey)
if err != nil {
logger.Fatal("failed-to-parse-host-key", err)
}
sshConfig.AddHostKey(key)
return sshConfig, err
}
示例13: TestRep
client, clientForServerThatErrors rep.Client
fakeLRPStopper *fake_lrp_stopper.FakeLRPStopper
fakeExecutorClient *executorfakes.FakeClient
fakeEvacuatable *fake_evacuation_context.FakeEvacuatable
)
func TestRep(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Rep Suite")
}
var _ = BeforeSuite(func() {
cfHttpTimeout = 1 * time.Second
cf_http.Initialize(cfHttpTimeout)
})
var _ = BeforeEach(func() {
logger := lagertest.NewTestLogger("test")
auctionRep = &repfakes.FakeClient{}
fakeLRPStopper = &fake_lrp_stopper.FakeLRPStopper{}
fakeExecutorClient = &executorfakes.FakeClient{}
fakeEvacuatable = &fake_evacuation_context.FakeEvacuatable{}
handler, err := rata.NewRouter(rep.Routes, handlers.New(auctionRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger))
Expect(err).NotTo(HaveOccurred())
server = httptest.NewServer(handler)
client = rep.NewClient(&http.Client{}, server.URL)
示例14: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
etcdFlags := AddETCDFlags(flag.CommandLine)
encryptionFlags := encryption.AddEncryptionFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("bbs")
logger.Info("starting")
initializeDropsonde(logger)
clock := clock.NewClock()
consulClient, err := consuladapter.NewClientFromUrl(*consulCluster)
if err != nil {
logger.Fatal("new-consul-client-failed", err)
}
serviceClient := bbs.NewServiceClient(consulClient, clock)
maintainer := initializeLockMaintainer(logger, serviceClient)
_, portString, err := net.SplitHostPort(*listenAddress)
if err != nil {
logger.Fatal("failed-invalid-listen-address", err)
}
portNum, err := net.LookupPort("tcp", portString)
if err != nil {
logger.Fatal("failed-invalid-listen-port", err)
}
_, portString, err = net.SplitHostPort(*healthAddress)
if err != nil {
logger.Fatal("failed-invalid-health-address", err)
}
_, err = net.LookupPort("tcp", portString)
if err != nil {
logger.Fatal("failed-invalid-health-port", err)
}
registrationRunner := initializeRegistrationRunner(logger, consulClient, portNum, clock)
cbWorkPool := taskworkpool.New(logger, *taskCallBackWorkers, taskworkpool.HandleCompletedTask)
var activeDB db.DB
var sqlDB *sqldb.SQLDB
var sqlConn *sql.DB
var storeClient etcddb.StoreClient
var etcdDB *etcddb.ETCDDB
key, keys, err := encryptionFlags.Parse()
if err != nil {
logger.Fatal("cannot-setup-encryption", err)
}
keyManager, err := encryption.NewKeyManager(key, keys)
if err != nil {
logger.Fatal("cannot-setup-encryption", err)
}
cryptor := encryption.NewCryptor(keyManager, rand.Reader)
etcdOptions, err := etcdFlags.Validate()
if err != nil {
logger.Fatal("etcd-validation-failed", err)
}
if etcdOptions.IsConfigured {
storeClient = initializeEtcdStoreClient(logger, etcdOptions)
etcdDB = initializeEtcdDB(logger, cryptor, storeClient, cbWorkPool, serviceClient, *desiredLRPCreationTimeout)
activeDB = etcdDB
}
// If SQL database info is passed in, use SQL instead of ETCD
if *databaseDriver != "" && *databaseConnectionString != "" {
var err error
connectionString := appendSSLConnectionStringParam(logger, *databaseDriver, *databaseConnectionString, *sqlCACertFile)
sqlConn, err = sql.Open(*databaseDriver, connectionString)
if err != nil {
logger.Fatal("failed-to-open-sql", err)
}
defer sqlConn.Close()
sqlConn.SetMaxOpenConns(*maxDatabaseConnections)
sqlConn.SetMaxIdleConns(*maxDatabaseConnections)
err = sqlConn.Ping()
if err != nil {
logger.Fatal("sql-failed-to-connect", err)
}
sqlDB = sqldb.NewSQLDB(sqlConn, *convergenceWorkers, *updateWorkers, format.ENCRYPTED_PROTO, cryptor, guidprovider.DefaultGuidProvider, clock, *databaseDriver)
err = sqlDB.CreateConfigurationsTable(logger)
if err != nil {
logger.Fatal("sql-failed-create-configurations-table", err)
}
activeDB = sqlDB
}
//.........這裏部分代碼省略.........
示例15: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
etcdFlags := AddETCDFlags(flag.CommandLine)
encryptionFlags := encryption.AddEncryptionFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("bbs")
logger.Info("starting")
initializeDropsonde(logger)
clock := clock.NewClock()
consulClient, err := consuladapter.NewClient(*consulCluster)
if err != nil {
logger.Fatal("new-consul-client-failed", err)
}
sessionManager := consuladapter.NewSessionManager(consulClient)
serviceClient := initializeServiceClient(logger, clock, consulClient, sessionManager)
cbWorkPool := taskworkpool.New(logger, *taskCallBackWorkers, taskworkpool.HandleCompletedTask)
keyManager, err := encryptionFlags.Validate()
if err != nil {
logger.Fatal("cannot-setup-encryption", err)
}
cryptor := encryption.NewCryptor(keyManager, rand.Reader)
etcdOptions, err := etcdFlags.Validate()
if err != nil {
logger.Fatal("etcd-validation-failed", err)
}
storeClient := initializeEtcdStoreClient(logger, etcdOptions)
db := initializeEtcdDB(logger, cryptor, storeClient, cbWorkPool, serviceClient)
migrationsDone := make(chan struct{})
maintainer := initializeLockMaintainer(logger, serviceClient)
migrationManager := migration.NewManager(logger,
db,
cryptor,
storeClient,
migrations.Migrations,
migrationsDone,
clock,
)
encryptor := encryptor.New(logger, db, keyManager, cryptor, storeClient, clock)
hub := events.NewHub()
watcher := watcher.NewWatcher(
logger,
db,
hub,
clock,
bbsWatchRetryWaitDuration,
)
handler := handlers.New(logger, db, hub, migrationsDone)
metricsNotifier := metrics.NewPeriodicMetronNotifier(
logger,
*reportInterval,
etcdOptions,
clock,
)
var server ifrit.Runner
if *requireSSL {
tlsConfig, err := cf_http.NewTLSConfig(*certFile, *keyFile, *caFile)
if err != nil {
logger.Fatal("tls-configuration-failed", err)
}
server = http_server.NewTLSServer(*listenAddress, handler, tlsConfig)
} else {
server = http_server.New(*listenAddress, handler)
}
members := grouper.Members{
{"lock-maintainer", maintainer},
{"workPool", cbWorkPool},
{"server", server},
{"migration-manager", migrationManager},
{"encryptor", encryptor},
{"watcher", watcher},
{"hub-closer", closeHub(logger.Session("hub-closer"), hub)},
{"metrics", *metricsNotifier},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
//.........這裏部分代碼省略.........