本文整理汇总了Golang中github.com/cloudfoundry/loggregator_consumer.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewRepositoryLocator
func NewRepositoryLocator(config core_config.ReadWriter, gatewaysByName map[string]net.Gateway) (loc RepositoryLocator) {
strategy := strategy.NewEndpointStrategy(config.ApiVersion())
cloudControllerGateway := gatewaysByName["cloud-controller"]
routingApiGateway := gatewaysByName["routing-api"]
uaaGateway := gatewaysByName["uaa"]
loc.authRepo = authentication.NewUAAAuthenticationRepository(uaaGateway, config)
// ensure gateway refreshers are set before passing them by value to repositories
cloudControllerGateway.SetTokenRefresher(loc.authRepo)
uaaGateway.SetTokenRefresher(loc.authRepo)
tlsConfig := net.NewTLSConfig([]tls.Certificate{}, config.IsSSLDisabled())
loggregatorConsumer := consumer.New(config.LoggregatorEndpoint(), tlsConfig, http.ProxyFromEnvironment)
loggregatorConsumer.SetDebugPrinter(terminal.DebugPrinter{})
noaaLib := noaa.NewConsumer(config.DopplerEndpoint(), tlsConfig, http.ProxyFromEnvironment)
noaaLib.SetDebugPrinter(terminal.DebugPrinter{})
logNoaaConsumer := NewNoaaConsumer(noaaLib)
loc.appBitsRepo = application_bits.NewCloudControllerApplicationBitsRepository(config, cloudControllerGateway)
loc.appEventsRepo = app_events.NewCloudControllerAppEventsRepository(config, cloudControllerGateway, strategy)
loc.appFilesRepo = api_app_files.NewCloudControllerAppFilesRepository(config, cloudControllerGateway)
loc.appRepo = applications.NewCloudControllerApplicationRepository(config, cloudControllerGateway)
loc.appSummaryRepo = NewCloudControllerAppSummaryRepository(config, cloudControllerGateway)
loc.appInstancesRepo = app_instances.NewCloudControllerAppInstancesRepository(config, cloudControllerGateway)
loc.authTokenRepo = NewCloudControllerServiceAuthTokenRepository(config, cloudControllerGateway)
loc.curlRepo = NewCloudControllerCurlRepository(config, cloudControllerGateway)
loc.domainRepo = NewCloudControllerDomainRepository(config, cloudControllerGateway, strategy)
loc.endpointRepo = NewEndpointRepository(config, cloudControllerGateway)
loc.logsNoaaRepo = NewLogsNoaaRepository(config, logNoaaConsumer, loc.authRepo)
loc.oldLogsRepo = NewLoggregatorLogsRepository(config, loggregatorConsumer, loc.authRepo)
loc.organizationRepo = organizations.NewCloudControllerOrganizationRepository(config, cloudControllerGateway)
loc.passwordRepo = password.NewCloudControllerPasswordRepository(config, uaaGateway)
loc.quotaRepo = quotas.NewCloudControllerQuotaRepository(config, cloudControllerGateway)
loc.routeRepo = NewCloudControllerRouteRepository(config, cloudControllerGateway)
loc.routingApiRepo = NewRoutingApiRepository(config, routingApiGateway)
loc.stackRepo = stacks.NewCloudControllerStackRepository(config, cloudControllerGateway)
loc.serviceRepo = NewCloudControllerServiceRepository(config, cloudControllerGateway)
loc.serviceKeyRepo = NewCloudControllerServiceKeyRepository(config, cloudControllerGateway)
loc.serviceBindingRepo = NewCloudControllerServiceBindingRepository(config, cloudControllerGateway)
loc.serviceBrokerRepo = NewCloudControllerServiceBrokerRepository(config, cloudControllerGateway)
loc.servicePlanRepo = NewCloudControllerServicePlanRepository(config, cloudControllerGateway)
loc.servicePlanVisibilityRepo = NewCloudControllerServicePlanVisibilityRepository(config, cloudControllerGateway)
loc.serviceSummaryRepo = NewCloudControllerServiceSummaryRepository(config, cloudControllerGateway)
loc.spaceRepo = spaces.NewCloudControllerSpaceRepository(config, cloudControllerGateway)
loc.userProvidedServiceInstanceRepo = NewCCUserProvidedServiceInstanceRepository(config, cloudControllerGateway)
loc.userRepo = NewCloudControllerUserRepository(config, uaaGateway, cloudControllerGateway)
loc.buildpackRepo = NewCloudControllerBuildpackRepository(config, cloudControllerGateway)
loc.buildpackBitsRepo = NewCloudControllerBuildpackBitsRepository(config, cloudControllerGateway, app_files.ApplicationZipper{})
loc.securityGroupRepo = security_groups.NewSecurityGroupRepo(config, cloudControllerGateway)
loc.stagingSecurityGroupRepo = staging.NewStagingSecurityGroupsRepo(config, cloudControllerGateway)
loc.runningSecurityGroupRepo = running.NewRunningSecurityGroupsRepo(config, cloudControllerGateway)
loc.securityGroupSpaceBinder = securitygroupspaces.NewSecurityGroupSpaceBinder(config, cloudControllerGateway)
loc.spaceQuotaRepo = space_quotas.NewCloudControllerSpaceQuotaRepository(config, cloudControllerGateway)
loc.featureFlagRepo = feature_flags.NewCloudControllerFeatureFlagRepository(config, cloudControllerGateway)
loc.environmentVariableGroupRepo = environment_variable_groups.NewCloudControllerEnvironmentVariableGroupsRepository(config, cloudControllerGateway)
loc.copyAppSourceRepo = copy_application_source.NewCloudControllerCopyApplicationSourceRepository(config, cloudControllerGateway)
return
}
示例2: main
func main() {
connection := consumer.New(LoggregatorAddress, &tls.Config{InsecureSkipVerify: true}, nil)
messages, err := connection.Recent(appGuid, authToken)
if err != nil {
fmt.Printf("===== Error getting recent messages: %v\n", err)
} else {
fmt.Println("===== Recent messages")
for _, msg := range messages {
fmt.Println(msg)
}
}
fmt.Println("===== Tailing messages")
msgChan, err := connection.Tail(appGuid, authToken)
if err != nil {
fmt.Printf("===== Error tailing: %v\n", err)
} else {
for msg := range msgChan {
fmt.Printf("%v \n", msg)
}
}
}
示例3: NewRepositoryLocator
func NewRepositoryLocator(config coreconfig.ReadWriter, gatewaysByName map[string]net.Gateway, logger trace.Printer, envDialTimeout string) (loc RepositoryLocator) {
strategy := strategy.NewEndpointStrategy(config.APIVersion())
cloudControllerGateway := gatewaysByName["cloud-controller"]
routingAPIGateway := gatewaysByName["routing-api"]
uaaGateway := gatewaysByName["uaa"]
loc.authRepo = authentication.NewUAARepository(uaaGateway, config, net.NewRequestDumper(logger))
// ensure gateway refreshers are set before passing them by value to repositories
cloudControllerGateway.SetTokenRefresher(loc.authRepo)
uaaGateway.SetTokenRefresher(loc.authRepo)
loc.appBitsRepo = applicationbits.NewCloudControllerApplicationBitsRepository(config, cloudControllerGateway)
loc.appEventsRepo = appevents.NewCloudControllerAppEventsRepository(config, cloudControllerGateway, strategy)
loc.appFilesRepo = api_appfiles.NewCloudControllerAppFilesRepository(config, cloudControllerGateway)
loc.appRepo = applications.NewCloudControllerRepository(config, cloudControllerGateway)
loc.appSummaryRepo = NewCloudControllerAppSummaryRepository(config, cloudControllerGateway)
loc.appInstancesRepo = appinstances.NewCloudControllerAppInstancesRepository(config, cloudControllerGateway)
loc.authTokenRepo = NewCloudControllerServiceAuthTokenRepository(config, cloudControllerGateway)
loc.curlRepo = NewCloudControllerCurlRepository(config, cloudControllerGateway)
loc.domainRepo = NewCloudControllerDomainRepository(config, cloudControllerGateway, strategy)
loc.endpointRepo = NewEndpointRepository(cloudControllerGateway)
tlsConfig := net.NewTLSConfig([]tls.Certificate{}, config.IsSSLDisabled())
apiVersion, _ := semver.Make(config.APIVersion())
var noaaRetryTimeout time.Duration
convertedTime, err := strconv.Atoi(envDialTimeout)
if err != nil {
noaaRetryTimeout = noaaRetryDefaultTimeout
} else {
noaaRetryTimeout = time.Duration(convertedTime) * 3 * time.Second
}
if apiVersion.GTE(cf.NoaaMinimumAPIVersion) {
consumer := consumer.New(config.DopplerEndpoint(), tlsConfig, http.ProxyFromEnvironment)
consumer.SetDebugPrinter(terminal.DebugPrinter{Logger: logger})
loc.logsRepo = logs.NewNoaaLogsRepository(config, consumer, loc.authRepo, noaaRetryTimeout)
} else {
consumer := loggregator_consumer.New(config.LoggregatorEndpoint(), tlsConfig, http.ProxyFromEnvironment)
consumer.SetDebugPrinter(terminal.DebugPrinter{Logger: logger})
loc.logsRepo = logs.NewLoggregatorLogsRepository(config, consumer, loc.authRepo)
}
loc.organizationRepo = organizations.NewCloudControllerOrganizationRepository(config, cloudControllerGateway)
loc.passwordRepo = password.NewCloudControllerRepository(config, uaaGateway)
loc.quotaRepo = quotas.NewCloudControllerQuotaRepository(config, cloudControllerGateway)
loc.routeRepo = NewCloudControllerRouteRepository(config, cloudControllerGateway)
loc.routeServiceBindingRepo = NewCloudControllerRouteServiceBindingRepository(config, cloudControllerGateway)
loc.routingAPIRepo = NewRoutingAPIRepository(config, routingAPIGateway)
loc.stackRepo = stacks.NewCloudControllerStackRepository(config, cloudControllerGateway)
loc.serviceRepo = NewCloudControllerServiceRepository(config, cloudControllerGateway)
loc.serviceKeyRepo = NewCloudControllerServiceKeyRepository(config, cloudControllerGateway)
loc.serviceBindingRepo = NewCloudControllerServiceBindingRepository(config, cloudControllerGateway)
loc.serviceBrokerRepo = NewCloudControllerServiceBrokerRepository(config, cloudControllerGateway)
loc.servicePlanRepo = NewCloudControllerServicePlanRepository(config, cloudControllerGateway)
loc.servicePlanVisibilityRepo = NewCloudControllerServicePlanVisibilityRepository(config, cloudControllerGateway)
loc.serviceSummaryRepo = NewCloudControllerServiceSummaryRepository(config, cloudControllerGateway)
loc.spaceRepo = spaces.NewCloudControllerSpaceRepository(config, cloudControllerGateway)
loc.userProvidedServiceInstanceRepo = NewCCUserProvidedServiceInstanceRepository(config, cloudControllerGateway)
loc.userRepo = NewCloudControllerUserRepository(config, uaaGateway, cloudControllerGateway)
loc.buildpackRepo = NewCloudControllerBuildpackRepository(config, cloudControllerGateway)
loc.buildpackBitsRepo = NewCloudControllerBuildpackBitsRepository(config, cloudControllerGateway, appfiles.ApplicationZipper{})
loc.securityGroupRepo = securitygroups.NewSecurityGroupRepo(config, cloudControllerGateway)
loc.stagingSecurityGroupRepo = staging.NewSecurityGroupsRepo(config, cloudControllerGateway)
loc.runningSecurityGroupRepo = running.NewSecurityGroupsRepo(config, cloudControllerGateway)
loc.securityGroupSpaceBinder = securitygroupspaces.NewSecurityGroupSpaceBinder(config, cloudControllerGateway)
loc.spaceQuotaRepo = spacequotas.NewCloudControllerSpaceQuotaRepository(config, cloudControllerGateway)
loc.featureFlagRepo = featureflags.NewCloudControllerFeatureFlagRepository(config, cloudControllerGateway)
loc.environmentVariableGroupRepo = environmentvariablegroups.NewCloudControllerRepository(config, cloudControllerGateway)
loc.copyAppSourceRepo = copyapplicationsource.NewCloudControllerCopyApplicationSourceRepository(config, cloudControllerGateway)
client := v3client.NewClient(config.APIEndpoint(), config.AuthenticationEndpoint(), config.AccessToken(), config.RefreshToken())
loc.v3Repository = repository.NewRepository(config, client)
return
}
示例4:
testServer.Close()
}
})
Describe("SetOnConnectCallback", func() {
BeforeEach(func() {
testServer = httptest.NewServer(handlers.NewWebsocketHandler(messagesToSend, 100*time.Millisecond))
endpoint = "ws://" + testServer.Listener.Addr().String()
close(messagesToSend)
})
It("sets a callback and calls it when connecting", func() {
called := false
cb := func() { called = true }
connection = consumer.New(endpoint, tlsSettings, nil)
connection.SetOnConnectCallback(cb)
connection.Tail(appGuid, authToken)
Eventually(func() bool { return called }).Should(BeTrue())
})
Context("when the connection fails", func() {
It("does not call the callback", func() {
endpoint = "!!!bad-endpoint"
called := false
cb := func() { called = true }
connection = consumer.New(endpoint, tlsSettings, nil)
connection.SetOnConnectCallback(cb)
示例5:
if testServer != nil {
testServer.Close()
}
})
Describe("SetOnConnectCallback", func() {
BeforeEach(func() {
testServer = httptest.NewServer(websocket.Handler(fakeHandler.handle))
endpoint = "ws://" + testServer.Listener.Addr().String()
})
It("sets a callback and calls it when connecting", func() {
called := false
cb := func() { called = true }
connection = consumer.New(endpoint, tlsSettings, nil)
connection.SetOnConnectCallback(cb)
connection.Tail(appGuid, authToken)
Eventually(func() bool { return called }).Should(BeTrue())
close(fakeHandler.closeConnection)
})
It("does not call the callback if the connection fails", func() {
endpoint = "!!!bad-endpoint"
called := false
cb := func() { called = true }
connection = consumer.New(endpoint, tlsSettings, nil)
connection.SetOnConnectCallback(cb)
示例6:
legacyEndpoint = fmt.Sprintf("ws://%s:%d", localIPAddress, TRAFFIC_CONTROLLER_LEGACY_PORT)
Eventually(func() error {
_, err := http.Get(fmt.Sprintf("http://%s:%d", localIPAddress, TRAFFIC_CONTROLLER_LEGACY_PORT))
return err
}).ShouldNot(HaveOccurred())
})
AfterEach(func() {
fakeDoppler.Stop()
})
Context("Streaming", func() {
It("delivers legacy format messages at legacy endpoint", func() {
legacy_consumer := loggregator_consumer.New(legacyEndpoint, &tls.Config{}, nil)
messages, err := legacy_consumer.Tail(APP_ID, AUTH_TOKEN)
Expect(err).NotTo(HaveOccurred())
var request *http.Request
Eventually(fakeDoppler.TrafficControllerConnected, 10).Should(Receive(&request))
Expect(request.URL.Path).To(Equal("/apps/1234/stream"))
currentTime := time.Now().UnixNano()
dropsondeMessage := makeDropsondeMessage("Make me Legacy Format", APP_ID, currentTime)
fakeDoppler.SendLogMessage(dropsondeMessage)
var receivedMessage *logmessage.LogMessage
Eventually(messages).Should(Receive(&receivedMessage))
Expect(receivedMessage.GetMessage()).To(BeEquivalentTo("Make me Legacy Format"))
示例7:
"os"
"io/ioutil"
"strings"
)
var _ = Describe("LoggregatorConsumer:", func() {
var appGuid, authToken string
var connection consumer.LoggregatorConsumer
BeforeEach(func() {
var err error
appGuid = os.Getenv("TEST_APP_GUID")
loggregatorEndpoint := os.Getenv("LOGGREGATOR_ENDPOINT")
connection = consumer.New(loggregatorEndpoint, &tls.Config{InsecureSkipVerify: true}, nil)
authToken, err = getAuthToken()
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
connection.Close()
})
It("should return data for recent", func() {
messages, err := connection.Recent(appGuid, authToken)
Expect(err).NotTo(HaveOccurred())
Expect(messages).To(ContainElement(ContainSubstring("Tick")))
})
示例8:
if testProxyServer != nil {
testProxyServer.Close()
}
if testServer != nil {
testServer.Close()
}
})
Describe("Tail", func() {
AfterEach(func() {
close(messagesToSend)
})
perform := func() {
connection = consumer.New(endpoint, tlsSettings, consumerProxyFunc)
incomingChan, err = connection.Tail(appGuid, authToken)
}
It("connects using valid URL to running consumerProxyFunc server", func() {
messagesToSend <- marshalMessage(createMessage("hello", 0))
perform()
message := <-incomingChan
Expect(message.Message).To(Equal([]byte("hello")))
})
It("connects using valid URL to a stopped consumerProxyFunc server", func() {
testProxyServer.Close()
示例9:
})
It("logs firehose access", func() {
noaaConsumer.Firehose("foo", AUTH_TOKEN)
expected := "CEF:0|cloud_foundry|loggregator_trafficcontroller|1.0|GET /firehose/foo|GET /firehose/foo|0|"
Eventually(testContents).Should(ContainSubstring(expected))
})
})
Context("with legacy endpoints", func() {
var legacyConsumer loggregator_consumer.LoggregatorConsumer
JustBeforeEach(func() {
tcURL := fmt.Sprintf("ws://%s:%d", localIPAddress, TRAFFIC_CONTROLLER_LEGACY_PORT)
legacyConsumer = loggregator_consumer.New(tcURL, &tls.Config{}, nil)
})
AfterEach(func() {
legacyConsumer.Close()
})
It("logs tail access", func() {
legacyConsumer.Tail(APP_ID, AUTH_TOKEN)
expected := fmt.Sprintf("CEF:0|cloud_foundry|loggregator_trafficcontroller|1.0|GET /tail/?app=%s|GET /tail/?app=%[1]s|0|", APP_ID)
Eventually(testContents).Should(ContainSubstring(expected))
})
It("logs recent access", func() {
legacyConsumer.Recent(APP_ID, AUTH_TOKEN)