本文整理匯總了Golang中github.com/zenazn/goji/web.Mux.ServeHTTP方法的典型用法代碼示例。如果您正苦於以下問題:Golang Mux.ServeHTTP方法的具體用法?Golang Mux.ServeHTTP怎麽用?Golang Mux.ServeHTTP使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/zenazn/goji/web.Mux
的用法示例。
在下文中一共展示了Mux.ServeHTTP方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
var mx *web.Mux // mux with the handlers we're testing
BeforeEach(func() {
settings = make(map[string]string)
mx = NewMux()
gojiutil.AddCommon15(mx, log15.Root())
mx.Use(gojiutil.ParamsLogger(true)) // useful for troubleshooting
})
It("gets what it sets", func() {
// set a value
req, _ := http.NewRequest("PUT", "http://example.com/settings/hello?value=world",
bytes.NewReader([]byte{}))
resp := httptest.NewRecorder()
mx.ServeHTTP(resp, req)
Ω(resp.Code).Should(Equal(200))
Ω(settings["hello"]).Should(Equal("world"))
// get the value back
req, _ = http.NewRequest("GET", "http://example.com/settings/hello", nil)
resp = httptest.NewRecorder()
mx.ServeHTTP(resp, req)
Ω(resp.Code).Should(Equal(200))
Ω(resp.Body.String()).Should(Equal("world"))
})
It("deletes and lists", func() {
// set a value
req, _ := http.NewRequest("PUT", "http://example.com/settings/hello?value=world",
bytes.NewReader([]byte{}))