当前位置: 首页>>代码示例>>Golang>>正文


Golang handlers.NewHttpHandler函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry/loggregatorlib/server/handlers.NewHttpHandler函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHttpHandler函数的具体用法?Golang NewHttpHandler怎么用?Golang NewHttpHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewHttpHandler函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ContainerMetricHandlerProvider

func ContainerMetricHandlerProvider(messages <-chan []byte, logger *gosteno.Logger) http.Handler {
	outputChan := DeDupe(messages)
	return handlers.NewHttpHandler(outputChan, logger)
}
开发者ID:lyuyun,项目名称:loggregator,代码行数:4,代码来源:doppler_endpoint.go

示例2:

			receivedLogMessages, recentError = connection.Recent(appGuid, authToken)
		}

		Context("when the connection cannot be established", func() {
			It("invalid endpoints return error", func() {
				endpoint = "invalid-endpoint"
				perform()

				Expect(recentError).ToNot(BeNil())
			})
		})

		Context("when the connection can be established", func() {

			BeforeEach(func() {
				testServer = httptest.NewServer(handlers.NewHttpHandler(messagesToSend))
				endpoint = "ws://" + testServer.Listener.Addr().String()
			})

			It("returns messages from the server", func() {
				messagesToSend <- marshalMessage(createMessage("test-message-0", 0))
				messagesToSend <- marshalMessage(createMessage("test-message-1", 0))

				perform()

				Expect(recentError).NotTo(HaveOccurred())
				Expect(receivedLogMessages).To(HaveLen(2))
				Expect(receivedLogMessages[0].Message).To(Equal([]byte("test-message-0")))
				Expect(receivedLogMessages[1].Message).To(Equal([]byte("test-message-1")))
			})
		})
开发者ID:matanzit,项目名称:cli,代码行数:31,代码来源:consumer_test.go

示例3:

			Expect(err.Error()).To(ContainSubstring(http.StatusText(http.StatusBadRequest)))
		})
	})

	Describe("RecentLogs", func() {
		var httpTestServer *httptest.Server
		var incomingMessages []*events.LogMessage

		perform := func() {
			close(messagesToSend)
			connection = noaa.NewConsumer(endpoint, tlsSettings, consumerProxyFunc)
			incomingMessages, err = connection.RecentLogs(appGuid, authToken)
		}

		BeforeEach(func() {
			httpTestServer = httptest.NewServer(handlers.NewHttpHandler(messagesToSend, loggertesthelper.Logger()))
			endpoint = "ws://" + httpTestServer.Listener.Addr().String()
		})

		AfterEach(func() {
			httpTestServer.Close()
		})

		It("returns messages from the server", func() {
			messagesToSend <- marshalMessage(createMessage("test-message-0", 0))
			messagesToSend <- marshalMessage(createMessage("test-message-1", 0))

			perform()

			Expect(err).NotTo(HaveOccurred())
			Expect(incomingMessages).To(HaveLen(2))
开发者ID:cwlbraa,项目名称:cf-acceptance-tests,代码行数:31,代码来源:consumer_proxy_test.go

示例4: HttpHandlerProvider

func HttpHandlerProvider(messages <-chan []byte, logger *gosteno.Logger) http.Handler {
	return handlers.NewHttpHandler(messages, logger)
}
开发者ID:lyuyun,项目名称:loggregator,代码行数:3,代码来源:doppler_endpoint.go

示例5:

			receivedLogMessages, recentError = connection.Recent(appGuid, authToken)
		}

		Context("when the connection cannot be established", func() {
			It("invalid endpoints return error", func() {
				endpoint = "invalid-endpoint"
				perform()

				Expect(recentError).ToNot(BeNil())
			})
		})

		Context("when the connection can be established", func() {

			BeforeEach(func() {
				testServer = httptest.NewServer(handlers.NewHttpHandler(messagesToSend, loggertesthelper.Logger()))
				endpoint = "ws://" + testServer.Listener.Addr().String()
			})

			It("returns messages from the server", func() {
				messagesToSend <- marshalMessage(createMessage("test-message-0", 0))
				messagesToSend <- marshalMessage(createMessage("test-message-1", 0))

				perform()

				Expect(recentError).NotTo(HaveOccurred())
				Expect(receivedLogMessages).To(HaveLen(2))
				Expect(receivedLogMessages[0].Message).To(Equal([]byte("test-message-0")))
				Expect(receivedLogMessages[1].Message).To(Equal([]byte("test-message-1")))
			})
		})
开发者ID:Doebe,项目名称:workplace,代码行数:31,代码来源:consumer_test.go

示例6:

			connection = noaa.NewConsumer(trafficControllerUrl, nil, nil)
			receivedLogMessages, recentError = connection.RecentLogs(appGuid, authToken)
		}

		Context("when the connection cannot be established", func() {
			It("invalid urls return error", func() {
				trafficControllerUrl = "invalid-url"
				perform()

				Expect(recentError).ToNot(BeNil())
			})
		})

		Context("when the connection can be established", func() {
			BeforeEach(func() {
				testServer = httptest.NewServer(handlers.NewHttpHandler(messagesToSend, loggertesthelper.Logger()))
				trafficControllerUrl = "ws://" + testServer.Listener.Addr().String()
			})

			It("returns messages from the server", func() {
				messagesToSend <- marshalMessage(createMessage("test-message-0", 0))
				messagesToSend <- marshalMessage(createMessage("test-message-1", 0))

				perform()

				Expect(recentError).NotTo(HaveOccurred())
				Expect(receivedLogMessages).To(HaveLen(2))
				Expect(receivedLogMessages[0].GetMessage()).To(Equal([]byte("test-message-0")))
				Expect(receivedLogMessages[1].GetMessage()).To(Equal([]byte("test-message-1")))
			})
		})
开发者ID:CA-APM,项目名称:epagent-nozzle,代码行数:31,代码来源:consumer_test.go

示例7:

		It("sets required CORS headers", func() {
			req, _ := http.NewRequest("POST", "/set-cookie", nil)
			req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
			req.Header.Set("Origin", "fake-origin-string")

			proxy.ServeHTTP(recorder, req)

			Expect(recorder.Header().Get("Access-Control-Allow-Origin")).To(Equal("fake-origin-string"))
			Expect(recorder.Header().Get("Access-Control-Allow-Credentials")).To(Equal("true"))
		})
	})
})

var _ = Describe("DefaultHandlerProvider", func() {
	It("returns an HTTP handler for .../recentlogs", func() {
		httpHandler := handlers.NewHttpHandler(make(chan []byte), loggertesthelper.Logger())

		target := doppler_endpoint.HttpHandlerProvider(make(chan []byte), loggertesthelper.Logger())

		Expect(target).To(BeAssignableToTypeOf(httpHandler))
	})

	It("returns a Websocket handler for .../stream", func() {
		wsHandler := handlers.NewWebsocketHandler(make(chan []byte), time.Minute, loggertesthelper.Logger())

		target := doppler_endpoint.WebsocketHandlerProvider(make(chan []byte), loggertesthelper.Logger())

		Expect(target).To(BeAssignableToTypeOf(wsHandler))
	})

	It("returns a Websocket handler for anything else", func() {
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:31,代码来源:doppler_proxy_test.go

示例8:

	"github.com/cloudfoundry/dropsonde/emitter"
	"github.com/cloudfoundry/dropsonde/factories"
	"github.com/cloudfoundry/loggregatorlib/server/handlers"
	"github.com/gogo/protobuf/proto"
	"time"
	"trafficcontroller/doppler_endpoint"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("NewDopplerEndpoint", func() {
	Context("when endpoint is 'recentlogs'", func() {
		It("uses an HTTP handler", func() {
			dopplerEndpoint := doppler_endpoint.NewDopplerEndpoint("recentlogs", "abc123", true)
			knownHttpHandler := handlers.NewHttpHandler(nil, nil)
			Expect(dopplerEndpoint.HProvider(nil, nil)).To(BeAssignableToTypeOf(knownHttpHandler))
		})

		It("sets a timeout of five seconds", func() {
			dopplerEndpoint := doppler_endpoint.NewDopplerEndpoint("recentlogs", "abc123", true)
			Expect(dopplerEndpoint.Timeout).To(Equal(5 * time.Second))
		})
	})

	Context("when endpoint is 'containermetrics'", func() {
		It("uses an HTTP Container metrics handler", func() {
			dopplerEndpoint := doppler_endpoint.NewDopplerEndpoint("containermetrics", "abc123", true)
			handler := handlers.NewHttpHandler(nil, nil)
			closedChan := make(chan []byte)
			close(closedChan)
开发者ID:lyuyun,项目名称:loggregator,代码行数:31,代码来源:doppler_endpoint_test.go

示例9:

	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/loggregatorlib/server/handlers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("HttpHandler", func() {
	var boundaryRegexp = regexp.MustCompile("boundary=(.*)")
	var handler http.Handler
	var fakeResponseWriter *httptest.ResponseRecorder
	var messagesChan chan []byte

	BeforeEach(func() {
		fakeResponseWriter = httptest.NewRecorder()
		messagesChan = make(chan []byte, 10)
		handler = handlers.NewHttpHandler(messagesChan, loggertesthelper.Logger())
	})

	It("grabs recent logs and creates a multi-part HTTP response", func(done Done) {
		r, _ := http.NewRequest("GET", "ws://loggregator.place/dump/?app=abc-123", nil)

		for i := 0; i < 5; i++ {
			messagesChan <- []byte("message")
		}

		close(messagesChan)
		handler.ServeHTTP(fakeResponseWriter, r)

		matches := boundaryRegexp.FindStringSubmatch(fakeResponseWriter.Header().Get("Content-Type"))
		Expect(matches).To(HaveLen(2))
		Expect(matches[1]).NotTo(BeEmpty())
开发者ID:pkdevbox,项目名称:loggregatorlib,代码行数:31,代码来源:http_handler_test.go

示例10:

			Expect(err.Error()).To(ContainSubstring(http.StatusText(http.StatusBadRequest)))
		})
	})

	Describe("Recent", func() {
		var httpTestServer *httptest.Server
		var incomingMessages []*logmessage.LogMessage

		perform := func() {
			close(messagesToSend)
			connection = consumer.New(endpoint, tlsSettings, consumerProxyFunc)
			incomingMessages, err = connection.Recent(appGuid, authToken)
		}

		BeforeEach(func() {
			httpTestServer = httptest.NewServer(handlers.NewHttpHandler(messagesToSend))
			endpoint = "ws://" + httpTestServer.Listener.Addr().String()
		})

		AfterEach(func() {
			httpTestServer.Close()
		})

		It("returns messages from the server", func() {
			messagesToSend <- marshalMessage(createMessage("test-message-0", 0))
			messagesToSend <- marshalMessage(createMessage("test-message-1", 0))

			perform()

			Expect(err).NotTo(HaveOccurred())
			Expect(incomingMessages).To(HaveLen(2))
开发者ID:hail100,项目名称:cli,代码行数:31,代码来源:consumer_proxy_test.go


注:本文中的github.com/cloudfoundry/loggregatorlib/server/handlers.NewHttpHandler函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。