• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang route.NewEndpoint函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: deleteEndpoints

func (r *RouteFetcher) deleteEndpoints(validRoutes []db.Route) {
	var diff []db.Route

	for _, curRoute := range r.endpoints {
		routeFound := false

		for _, validRoute := range validRoutes {
			if routeEquals(curRoute, validRoute) {
				routeFound = true
				break
			}
		}

		if !routeFound {
			diff = append(diff, curRoute)
			r.endpoints = r.endpoints
		}
	}

	for _, aRoute := range diff {
		r.RouteRegistry.Unregister(
			route.Uri(aRoute.Route),
			route.NewEndpoint(
				aRoute.LogGuid,
				aRoute.IP,
				uint16(aRoute.Port),
				aRoute.LogGuid,
				nil,
				aRoute.TTL,
				aRoute.RouteServiceUrl,
			))
	}
}
开发者ID:nagyistge,项目名称:gorouter,代码行数:33,代码来源:route_fetcher.go


示例2: registerAddr

func registerAddr(reg *registry.RouteRegistry, path string, routeServiceUrl string, addr net.Addr, instanceId string) {
	host, portStr, err := net.SplitHostPort(addr.String())
	Expect(err).NotTo(HaveOccurred())

	port, err := strconv.Atoi(portStr)
	Expect(err).NotTo(HaveOccurred())

	reg.Register(route.Uri(path), route.NewEndpoint("", host, uint16(port), instanceId, nil, -1, routeServiceUrl))
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:9,代码来源:proxy_test.go


示例3: registerAddr

func registerAddr(r *registry.RouteRegistry, u string, a net.Addr, instanceId string) {
	h, p, err := net.SplitHostPort(a.String())
	Ω(err).NotTo(HaveOccurred())

	x, err := strconv.Atoi(p)
	Ω(err).NotTo(HaveOccurred())

	r.Register(route.Uri(u), route.NewEndpoint("", h, uint16(x), instanceId, nil))
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:9,代码来源:proxy_test.go


示例4: makeEndpoint

func (rm *RegistryMessage) makeEndpoint() *route.Endpoint {
	return route.NewEndpoint(
		rm.App,
		rm.Host,
		rm.Port,
		rm.PrivateInstanceId,
		rm.Tags,
		rm.StaleThresholdInSeconds,
		rm.RouteServiceUrl,
		models.ModificationTag{})
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:11,代码来源:router.go


示例5: HandleEvent

func (r *RouteFetcher) HandleEvent(e routing_api.Event) {
	eventRoute := e.Route
	uri := route.Uri(eventRoute.Route)
	endpoint := route.NewEndpoint(eventRoute.LogGuid, eventRoute.IP, uint16(eventRoute.Port), eventRoute.LogGuid, nil, eventRoute.TTL, eventRoute.RouteServiceUrl)
	switch e.Action {
	case "Delete":
		r.RouteRegistry.Unregister(uri, endpoint)
	case "Upsert":
		r.RouteRegistry.Register(uri, endpoint)
	}
}
开发者ID:nagyistge,项目名称:gorouter,代码行数:11,代码来源:route_fetcher.go


示例6: HandleEvent

func (r *RouteFetcher) HandleEvent(e routing_api.Event) error {
	r.logger.Infof("Handling event: %v", e)
	eventRoute := e.Route
	uri := route.Uri(eventRoute.Route)
	endpoint := route.NewEndpoint(eventRoute.LogGuid, eventRoute.IP, uint16(eventRoute.Port), eventRoute.LogGuid, nil, eventRoute.TTL)
	switch e.Action {
	case "Delete":
		r.RouteRegistry.Unregister(uri, endpoint)
	case "Upsert":
		r.RouteRegistry.Register(uri, endpoint)
	}

	r.logger.Infof("Successfully handled event: %v", e)
	return nil
}
开发者ID:trainchou,项目名称:gorouter,代码行数:15,代码来源:route_fetcher.go


示例7: refreshEndpoints

func (r *RouteFetcher) refreshEndpoints(validRoutes []db.Route) {
	r.deleteEndpoints(validRoutes)

	r.endpoints = validRoutes

	for _, aRoute := range r.endpoints {
		r.RouteRegistry.Register(
			route.Uri(aRoute.Route),
			route.NewEndpoint(
				aRoute.LogGuid,
				aRoute.IP,
				uint16(aRoute.Port),
				aRoute.LogGuid,
				nil,
				aRoute.TTL,
			))
	}
}
开发者ID:trainchou,项目名称:gorouter,代码行数:18,代码来源:route_fetcher.go


示例8: refreshEndpoints

func (r *RouteFetcher) refreshEndpoints(validRoutes []models.Route) {
	r.deleteEndpoints(validRoutes)

	r.endpoints = validRoutes

	for _, aRoute := range r.endpoints {
		r.RouteRegistry.Register(
			route.Uri(aRoute.Route),
			route.NewEndpoint(
				aRoute.LogGuid,
				aRoute.IP,
				uint16(aRoute.Port),
				aRoute.LogGuid,
				nil,
				aRoute.GetTTL(),
				aRoute.RouteServiceUrl,
				aRoute.ModificationTag,
			))
	}
}
开发者ID:rakutentech,项目名称:gorouter,代码行数:20,代码来源:route_fetcher.go


示例9: CreateAccessLogRecord

func CreateAccessLogRecord() *AccessLogRecord {
	u, err := url.Parse("http://foo.bar:1234/quz?wat")
	if err != nil {
		panic(err)
	}

	req := &http.Request{
		Method:     "GET",
		URL:        u,
		Proto:      "HTTP/1.1",
		Header:     make(http.Header),
		Host:       "foo.bar",
		RemoteAddr: "1.2.3.4:5678",
	}

	req.Header.Set("Referer", "referer")
	req.Header.Set("User-Agent", "user-agent")

	res := &http.Response{
		StatusCode: http.StatusOK,
	}

	b := route.NewEndpoint("my_awesome_id", "127.0.0.1", 4567, "", nil)

	r := AccessLogRecord{
		Request:       req,
		StatusCode:    res.StatusCode,
		RouteEndpoint: b,
		StartedAt:     time.Unix(10, 100000000),
		FirstByteAt:   time.Unix(10, 200000000),
		FinishedAt:    time.Unix(10, 300000000),
		BodyBytesSent: 42,
	}

	return &r
}
开发者ID:KeyOfSpectator,项目名称:gorouter,代码行数:36,代码来源:file_and_loggregator_access_logger_test.go


示例10:

	"github.com/cloudfoundry/gorouter/route"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("EndpointIterator", func() {
	var pool *route.Pool

	BeforeEach(func() {
		pool = route.NewPool(2*time.Minute, "")
	})

	Describe("Next", func() {
		It("performs round-robin through the endpoints", func() {
			e1 := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "")
			e2 := route.NewEndpoint("", "5.6.7.8", 1234, "", nil, -1, "")
			e3 := route.NewEndpoint("", "1.2.7.8", 1234, "", nil, -1, "")
			endpoints := []*route.Endpoint{e1, e2, e3}

			for _, e := range endpoints {
				pool.Put(e)
			}

			counts := make([]int, len(endpoints))

			iter := pool.Endpoints("")

			loops := 50
			for i := 0; i < len(endpoints)*loops; i += 1 {
				n := iter.Next()
开发者ID:yingkitw,项目名称:gorouter,代码行数:30,代码来源:endpoint_iterator_test.go


示例11:

	var r *RouteRegistry
	var messageBus *fakeyagnats.FakeNATSConn

	var fooEndpoint, barEndpoint, bar2Endpoint *route.Endpoint
	var configObj *config.Config

	BeforeEach(func() {
		configObj = config.DefaultConfig()
		configObj.PruneStaleDropletsInterval = 50 * time.Millisecond
		configObj.DropletStaleThreshold = 10 * time.Millisecond

		messageBus = fakeyagnats.Connect()
		r = NewRouteRegistry(configObj, messageBus)
		fooEndpoint = route.NewEndpoint("12345", "192.168.1.1", 1234,
			"id1", map[string]string{
				"runtime":   "ruby18",
				"framework": "sinatra",
			}, -1, "")

		barEndpoint = route.NewEndpoint("54321", "192.168.1.2", 4321,
			"id2", map[string]string{
				"runtime":   "javascript",
				"framework": "node",
			}, -1, "https://my-rs.com")

		bar2Endpoint = route.NewEndpoint("54321", "192.168.1.3", 1234,
			"id3", map[string]string{
				"runtime":   "javascript",
				"framework": "node",
			}, -1, "")
	})
开发者ID:janitorsun,项目名称:gorouter,代码行数:31,代码来源:registry_test.go


示例12:

			go accessLogger.Run()

			accessLogger.Log(*CreateAccessLogRecord())
			Eventually(testEmitter.done).Should(Receive())
			Ω(testEmitter.emitted).Should(BeTrue())
			Ω(testEmitter.appId).To(Equal("my_awesome_id"))
			Ω(testEmitter.message).To(MatchRegexp("^.*foo.bar.*\n"))

			accessLogger.Stop()
		})

		It("a record with no app id is not written", func() {
			testEmitter := NewMockEmitter()
			accessLogger := NewFileAndLoggregatorAccessLogger(nil, testEmitter)

			routeEndpoint := route.NewEndpoint("", "127.0.0.1", 4567, "", nil)

			accessLogRecord := CreateAccessLogRecord()
			accessLogRecord.RouteEndpoint = routeEndpoint
			accessLogger.Log(*accessLogRecord)
			go accessLogger.Run()

			Consistently(testEmitter.done).ShouldNot(Receive())

			accessLogger.Stop()
		})

	})

	Context("with a file", func() {
		It("writes to the log file", func() {
开发者ID:KeyOfSpectator,项目名称:gorouter,代码行数:31,代码来源:file_and_loggregator_access_logger_test.go


示例13:

			client.RoutesReturns(response, nil)

			err := fetcher.FetchRoutes()
			Expect(err).ToNot(HaveOccurred())

			Expect(registry.RegisterCallCount()).To(Equal(3))

			for i := 0; i < 3; i++ {
				expectedRoute := response[i]
				uri, endpoint := registry.RegisterArgsForCall(i)
				Expect(uri).To(Equal(route.Uri(expectedRoute.Route)))
				Expect(endpoint).To(Equal(
					route.NewEndpoint(expectedRoute.LogGuid,
						expectedRoute.IP, uint16(expectedRoute.Port),
						expectedRoute.LogGuid,
						nil,
						expectedRoute.TTL,
						expectedRoute.RouteServiceUrl,
					)))
			}
		})

		It("uses cache when fetching token from UAA", func() {
			client.RoutesReturns(response, nil)

			err := fetcher.FetchRoutes()
			Expect(err).ToNot(HaveOccurred())
			Expect(uaaClient.FetchTokenCallCount()).To(Equal(1))
			Expect(uaaClient.FetchTokenArgsForCall(0)).To(Equal(false))
		})
开发者ID:yingkitw,项目名称:gorouter,代码行数:30,代码来源:route_fetcher_test.go


示例14: makeEndpoint

func (rm *registryMessage) makeEndpoint() *route.Endpoint {
	return route.NewEndpoint(rm.App, rm.Host, rm.Port, rm.PrivateInstanceId, rm.Tags)
}
开发者ID:KeyOfSpectator,项目名称:gorouter,代码行数:3,代码来源:registry_message.go


示例15:

	var r *RouteRegistry
	var messageBus *fakeyagnats.FakeYagnats

	var fooEndpoint, barEndpoint, bar2Endpoint *route.Endpoint
	var configObj *config.Config

	BeforeEach(func() {
		configObj = config.DefaultConfig()
		configObj.PruneStaleDropletsInterval = 50 * time.Millisecond
		configObj.DropletStaleThreshold = 10 * time.Millisecond

		messageBus = fakeyagnats.New()
		r = NewRouteRegistry(configObj, messageBus)
		fooEndpoint = route.NewEndpoint("12345", "192.168.1.1", 1234,
			"id1", map[string]string{
				"runtime":   "ruby18",
				"framework": "sinatra",
			})

		barEndpoint = route.NewEndpoint("54321", "192.168.1.2", 4321,
			"id2", map[string]string{
				"runtime":   "javascript",
				"framework": "node",
			})

		bar2Endpoint = route.NewEndpoint("54321", "192.168.1.3", 1234,
			"id3", map[string]string{
				"runtime":   "javascript",
				"framework": "node",
			})
	})
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:31,代码来源:registry_test.go


示例16:

var _ = Describe("AccessLogRecord", func() {
	Measure("Register", func(b Benchmarker) {
		c := config.DefaultConfig()
		mbus := fakeyagnats.NewApceraClientWrapper()
		r := registry.NewRouteRegistry(c, mbus)

		accesslog, err := access_log.CreateRunningAccessLogger(c)
		Ω(err).ToNot(HaveOccurred())

		proxy.NewProxy(proxy.ProxyArgs{
			EndpointTimeout: c.EndpointTimeout,
			Ip:              c.Ip,
			TraceKey:        c.TraceKey,
			Registry:        r,
			Reporter:        varz.NewVarz(r),
			AccessLogger:    accesslog,
		})

		b.Time("RegisterTime", func() {
			for i := 0; i < 1000; i++ {
				str := strconv.Itoa(i)
				r.Register(
					route.Uri("bench.vcap.me."+str),
					route.NewEndpoint("", "localhost", uint16(i), "", nil),
				)
			}
		})
	}, 10)

})
开发者ID:johannespetzold,项目名称:gorouter,代码行数:30,代码来源:perf_test.go


示例17:

		})

		It("updates the route registry", func() {
			client.RoutesReturns(response, nil)

			err := fetcher.FetchRoutes()
			Expect(err).ToNot(HaveOccurred())

			Expect(registry.RegisterCallCount()).To(Equal(3))

			for i := 0; i < 3; i++ {
				response := response[i]
				uri, endpoint := registry.RegisterArgsForCall(i)
				Expect(uri).To(Equal(route.Uri(response.Route)))
				Expect(endpoint).To(Equal(route.NewEndpoint(response.LogGuid, response.IP, uint16(response.Port), response.LogGuid, nil, response.TTL)))
			}
		})

		It("removes unregistered routes", func() {
			secondResponse := []db.Route{
				response[0],
			}

			client.RoutesReturns(response, nil)

			err := fetcher.FetchRoutes()
			Expect(err).ToNot(HaveOccurred())
			Expect(registry.RegisterCallCount()).To(Equal(3))

			client.RoutesReturns(secondResponse, nil)
开发者ID:trainchou,项目名称:gorouter,代码行数:30,代码来源:route_fetcher_test.go


示例18:

var _ = Describe("AccessLogRecord", func() {
	Measure("Register", func(b Benchmarker) {
		logger := lagertest.NewTestLogger("test")
		c := config.DefaultConfig()
		r := registry.NewRouteRegistry(logger, c, new(fakes.FakeRouteRegistryReporter))

		accesslog, err := access_log.CreateRunningAccessLogger(logger, c)
		Expect(err).ToNot(HaveOccurred())

		proxy.NewProxy(proxy.ProxyArgs{
			EndpointTimeout: c.EndpointTimeout,
			Ip:              c.Ip,
			TraceKey:        c.TraceKey,
			Registry:        r,
			Reporter:        varz.NewVarz(r),
			AccessLogger:    accesslog,
		})

		b.Time("RegisterTime", func() {
			for i := 0; i < 1000; i++ {
				str := strconv.Itoa(i)
				r.Register(
					route.Uri("bench.vcap.me."+str),
					route.NewEndpoint("", "localhost", uint16(i), "", nil, -1, "", models.ModificationTag{}),
				)
			}
		})
	}, 10)

})
开发者ID:rakutentech,项目名称:gorouter,代码行数:30,代码来源:perf_test.go


示例19:

	})

	It("reports seconds since last registry update", func() {
		Registry.Register("foo", &route.Endpoint{})

		time.Sleep(10 * time.Millisecond)

		timeSince := findValue(Varz, "ms_since_last_registry_update").(float64)
		Expect(timeSince).To(BeNumerically("<", 1000))
		Expect(timeSince).To(BeNumerically(">=", 10))
	})

	It("has urls", func() {
		Expect(findValue(Varz, "urls")).To(Equal(float64(0)))

		var fooReg = route.NewEndpoint("12345", "192.168.1.1", 1234, "", map[string]string{}, -1, "", models.ModificationTag{})

		// Add a route
		Registry.Register("foo.vcap.me", fooReg)
		Registry.Register("fooo.vcap.me", fooReg)

		Expect(findValue(Varz, "urls")).To(Equal(float64(2)))
	})

	It("updates bad requests", func() {
		r := http.Request{}

		Varz.CaptureBadRequest(&r)
		Expect(findValue(Varz, "bad_requests")).To(Equal(float64(1)))

		Varz.CaptureBadRequest(&r)
开发者ID:rakutentech,项目名称:gorouter,代码行数:31,代码来源:varz_test.go


示例20:

	var fakeReporter2 *fakes.FakeProxyReporter
	var composite reporter.ProxyReporter

	var req *http.Request
	var endpoint *route.Endpoint
	var response *http.Response
	var responseTime time.Time
	var responseDuration time.Duration

	BeforeEach(func() {
		fakeReporter1 = new(fakes.FakeProxyReporter)
		fakeReporter2 = new(fakes.FakeProxyReporter)

		composite = metrics.NewCompositeReporter(fakeReporter1, fakeReporter2)
		req, _ = http.NewRequest("GET", "https://example.com", nil)
		endpoint = route.NewEndpoint("someId", "host", 2222, "privateId", map[string]string{}, 30, "", models.ModificationTag{})
		response = &http.Response{StatusCode: 200}
		responseTime = time.Now()
		responseDuration = time.Second
	})

	It("forwards CaptureBadRequest to both reporters", func() {
		composite.CaptureBadRequest(req)

		Expect(fakeReporter1.CaptureBadRequestCallCount()).To(Equal(1))
		Expect(fakeReporter2.CaptureBadRequestCallCount()).To(Equal(1))

		Expect(fakeReporter1.CaptureBadRequestArgsForCall(0)).To(Equal(req))
		Expect(fakeReporter2.CaptureBadRequestArgsForCall(0)).To(Equal(req))
	})
开发者ID:rakutentech,项目名称:gorouter,代码行数:30,代码来源:composite_reporter_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang route.Uri函数代码示例发布时间:2022-05-23
下一篇:
Golang fakes.FakeRegistryInterface类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap