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


Golang ServiceConfig.ErrorPages方法代码示例

本文整理汇总了Golang中github.com/skyfii/shuttle/client.ServiceConfig.ErrorPages方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceConfig.ErrorPages方法的具体用法?Golang ServiceConfig.ErrorPages怎么用?Golang ServiceConfig.ErrorPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/skyfii/shuttle/client.ServiceConfig的用法示例。


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

示例1: TestMaintenanceMode

func (s *HTTPSuite) TestMaintenanceMode(c *C) {
	mainServer := s.backendServers[0]
	errServer := s.backendServers[1]

	svcCfg := client.ServiceConfig{
		Name:         "VHostTest1",
		Addr:         "127.0.0.1:9000",
		VirtualHosts: []string{"vhost1.test"},
		Backends: []client.BackendConfig{
			{Addr: mainServer.addr},
		},
		MaintenanceMode: true,
	}

	if err := Registry.AddService(svcCfg); err != nil {
		c.Fatal(err)
	}

	// No error page is registered, so we should just get a 503 error with no body
	checkHTTP("https://vhost1.test:"+s.httpsPort+"/addr", "vhost1.test", "", 503, c)

	// Use another backend to provide the error page
	svcCfg.ErrorPages = map[string][]int{
		"http://" + errServer.addr + "/error?code=503": []int{503},
	}

	if err := Registry.UpdateService(svcCfg); err != nil {
		c.Fatal(err)
	}

	// Get a 503 error with the cached body
	checkHTTP("https://vhost1.test:"+s.httpsPort+"/addr", "vhost1.test", errServer.addr, 503, c)

	// Turn maintenance mode off
	svcCfg.MaintenanceMode = false

	if err := Registry.UpdateService(svcCfg); err != nil {
		c.Fatal(err)
	}

	checkHTTP("https://vhost1.test:"+s.httpsPort+"/addr", "vhost1.test", mainServer.addr, 200, c)

	// Turn it back on
	svcCfg.MaintenanceMode = true

	if err := Registry.UpdateService(svcCfg); err != nil {
		c.Fatal(err)
	}

	checkHTTP("https://vhost1.test:"+s.httpsPort+"/addr", "vhost1.test", errServer.addr, 503, c)
}
开发者ID:skyfii,项目名称:shuttle,代码行数:51,代码来源:admin_test.go

示例2: 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)
}
开发者ID:skyfii,项目名称:shuttle,代码行数:49,代码来源:admin_test.go


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