本文整理汇总了Golang中github.com/litl/shuttle/client.ServiceConfig.ErrorPages方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceConfig.ErrorPages方法的具体用法?Golang ServiceConfig.ErrorPages怎么用?Golang ServiceConfig.ErrorPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/litl/shuttle/client.ServiceConfig
的用法示例。
在下文中一共展示了ServiceConfig.ErrorPages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestErrorPage
func (s *HTTPSuite) TestErrorPage(c *C) {
svcCfg := client.ServiceConfig{
Name: "VHostTest",
Addr: "127.0.0.1:9000",
VirtualHosts: []string{"test-vhost"},
}
okServer := s.backendServers[0]
errServer := s.backendServers[1]
// Add one backend to service requests
cfg := client.BackendConfig{
Addr: okServer.addr,
Name: okServer.addr,
}
svcCfg.Backends = append(svcCfg.Backends, cfg)
// use another backend to provide the error page
svcCfg.ErrorPages = map[string][]int{
"http://" + errServer.addr + "/error": []int{400, 503},
}
err := Registry.AddService(svcCfg)
if err != nil {
c.Fatal(err)
}
// check that the normal response comes from srv1
checkHTTP("http://"+s.httpAddr+"/addr", "test-vhost", okServer.addr, 200, c)
// verify that an unregistered error doesn't give the cached page
checkHTTP("http://"+s.httpAddr+"/error?code=504", "test-vhost", okServer.addr, 504, c)
// now see if the registered error comes from srv2
checkHTTP("http://"+s.httpAddr+"/error?code=503", "test-vhost", errServer.addr, 503, c)
// now check that we got the header cached in the error page as well
req, err := http.NewRequest("GET", "http://"+s.httpAddr+"/error?code=503", nil)
if err != nil {
c.Fatal(err)
}
req.Host = "test-vhost"
resp, err := http.DefaultClient.Do(req)
if err != nil {
c.Fatal(err)
}
c.Assert(resp.StatusCode, Equals, 503)
c.Assert(resp.Header.Get("Last-Modified"), Equals, errServer.addr)
}