Esempio n. 1
0
// Example with direct usage
func ExampleNewRoundRobinClb() {
	srvName := "foo.service.fliglio.com"
	lib := dns.NewLookupLib("8.8.8.8:53")
	c := NewRoundRobinClb(lib)
	address, err := c.GetAddress(srvName)
	if err != nil {
		fmt.Print(err)
	}

	if address.Port == 8001 {
		fmt.Printf("%s", address)
	} else {
		address2, err := c.GetAddress(srvName)
		if err != nil {
			fmt.Print(err)
		}
		fmt.Printf("%s", address2)
	}
	// Output: 0.1.2.3:8001
}
Esempio n. 2
0
//strconv.FormatInt(int64(srv.Port), 10)
func TestRandomLookup(t *testing.T) {
	// given
	srvName := "foo.service.fliglio.com"
	lib := dns.NewLookupLib("8.8.8.8:53")
	c := NewRandomClb(lib)

	// when
	address, err := c.GetAddress(srvName)

	// then
	if err != nil {
		t.Error(err)
	}

	if address.Port == 8001 && address.Address == "0.1.2.3" {
		return
	} else if address.Port == 8002 && address.Address == "4.5.6.7" {
		return
	} else {
		t.Errorf("port '%d' not expected with address: '%s'", address.Port, address.Address)
	}
}
Esempio n. 3
0
func NewTtlCacheClb(address string, port string, lbType LoadBalancerType, ttl int32) LoadBalancer {
	lib := dns.NewLookupLib(fmt.Sprintf("%s:%s", address, port))
	cache := ttlcache.NewTtlCache(lib, ttl)

	return buildClb(cache, lbType)
}
Esempio n. 4
0
func NewClb(address string, port string, lbType LoadBalancerType) LoadBalancer {
	lib := dns.NewLookupLib(fmt.Sprintf("%s:%s", address, port))

	return buildClb(lib, lbType)
}