本文整理匯總了Golang中github.com/cloudfoundry/gorouter/route.NewEndpoint函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewEndpoint函數的具體用法?Golang NewEndpoint怎麽用?Golang NewEndpoint使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewEndpoint函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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,
))
}
}
示例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))
}
示例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))
}
示例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{})
}
示例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)
}
}
示例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
}
示例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,
))
}
}
示例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,
))
}
}
示例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
}
示例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()
示例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, "")
})
示例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() {
示例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))
})
示例14: makeEndpoint
func (rm *registryMessage) makeEndpoint() *route.Endpoint {
return route.NewEndpoint(rm.App, rm.Host, rm.Port, rm.PrivateInstanceId, rm.Tags)
}
示例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",
})
})