Merge pull request #571 from micro/remove-port
Remove Port from registry
This commit is contained in:
commit
d3edad474e
@ -73,7 +73,7 @@ func (h *httpHandler) getService(r *http.Request) (string, error) {
|
|||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("http://%s:%d", s.Address, s.Port), nil
|
return fmt.Sprintf("http://%s", s.Address), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpHandler) String() string {
|
func (h *httpHandler) String() string {
|
||||||
|
@ -4,8 +4,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/micro/go-micro/api/handler"
|
"github.com/micro/go-micro/api/handler"
|
||||||
@ -26,21 +24,12 @@ func testHttp(t *testing.T, path, service, ns string) {
|
|||||||
}
|
}
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
|
|
||||||
parts := strings.Split(l.Addr().String(), ":")
|
|
||||||
|
|
||||||
var host string
|
|
||||||
var port int
|
|
||||||
|
|
||||||
host = parts[0]
|
|
||||||
port, _ = strconv.Atoi(parts[1])
|
|
||||||
|
|
||||||
s := ®istry.Service{
|
s := ®istry.Service{
|
||||||
Name: service,
|
Name: service,
|
||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
®istry.Node{
|
®istry.Node{
|
||||||
Id: service + "-1",
|
Id: service + "-1",
|
||||||
Address: host,
|
Address: l.Addr().String(),
|
||||||
Port: port,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ func (wh *webHandler) getService(r *http.Request) (string, error) {
|
|||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("http://%s:%d", s.Address, s.Port), nil
|
return fmt.Sprintf("http://%s", s.Address), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// serveWebSocket used to serve a web socket proxied connection
|
// serveWebSocket used to serve a web socket proxied connection
|
||||||
|
@ -14,13 +14,11 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-123",
|
Id: "foo-1.0.0-123",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-321",
|
Id: "foo-1.0.0-321",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -30,8 +28,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.1-321",
|
Id: "foo-1.0.1-321",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -41,8 +38,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.3-345",
|
Id: "foo-1.0.3-345",
|
||||||
Address: "localhost",
|
Address: "localhost:8888",
|
||||||
Port: 8888,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -543,7 +543,7 @@ func (h *httpBroker) Publish(topic string, msg *Message, opts ...PublishOption)
|
|||||||
vals := url.Values{}
|
vals := url.Values{}
|
||||||
vals.Add("id", node.Id)
|
vals.Add("id", node.Id)
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s://%s:%d%s?%s", scheme, node.Address, node.Port, DefaultSubPath, vals.Encode())
|
uri := fmt.Sprintf("%s://%s%s?%s", scheme, node.Address, DefaultSubPath, vals.Encode())
|
||||||
r, err := h.c.Post(uri, "application/json", bytes.NewReader(b))
|
r, err := h.c.Post(uri, "application/json", bytes.NewReader(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -638,8 +638,7 @@ func (h *httpBroker) Subscribe(topic string, handler Handler, opts ...SubscribeO
|
|||||||
// register service
|
// register service
|
||||||
node := ®istry.Node{
|
node := ®istry.Node{
|
||||||
Id: id,
|
Id: id,
|
||||||
Address: addr,
|
Address: fmt.Sprintf("%s:%d", addr, port),
|
||||||
Port: port,
|
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"secure": fmt.Sprintf("%t", secure),
|
"secure": fmt.Sprintf("%t", secure),
|
||||||
},
|
},
|
||||||
|
@ -14,13 +14,11 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-123",
|
Id: "foo-1.0.0-123",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-321",
|
Id: "foo-1.0.0-321",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -30,8 +28,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.1-321",
|
Id: "foo-1.0.1-321",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -41,8 +38,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.3-345",
|
Id: "foo-1.0.3-345",
|
||||||
Address: "localhost",
|
Address: "localhost:8888",
|
||||||
Port: 8888,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -84,9 +84,6 @@ func (g *grpcClient) next(request client.Request, opts client.CallOptions) (sele
|
|||||||
|
|
||||||
func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
||||||
address := node.Address
|
address := node.Address
|
||||||
if node.Port > 0 {
|
|
||||||
address = fmt.Sprintf("%s:%d", address, node.Port)
|
|
||||||
}
|
|
||||||
|
|
||||||
header := make(map[string]string)
|
header := make(map[string]string)
|
||||||
if md, ok := metadata.FromContext(ctx); ok {
|
if md, ok := metadata.FromContext(ctx); ok {
|
||||||
@ -146,9 +143,6 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R
|
|||||||
|
|
||||||
func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client.Request, opts client.CallOptions) (client.Stream, error) {
|
func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client.Request, opts client.CallOptions) (client.Stream, error) {
|
||||||
address := node.Address
|
address := node.Address
|
||||||
if node.Port > 0 {
|
|
||||||
address = fmt.Sprintf("%s:%d", address, node.Port)
|
|
||||||
}
|
|
||||||
|
|
||||||
header := make(map[string]string)
|
header := make(map[string]string)
|
||||||
if md, ok := metadata.FromContext(ctx); ok {
|
if md, ok := metadata.FromContext(ctx); ok {
|
||||||
|
@ -2,6 +2,7 @@ package grpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -50,8 +51,7 @@ func TestGRPCClient(t *testing.T) {
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
®istry.Node{
|
®istry.Node{
|
||||||
Id: "test-1",
|
Id: "test-1",
|
||||||
Address: addr,
|
Address: fmt.Sprintf("%s:%d", addr, port),
|
||||||
Port: port,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -4,9 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -60,9 +58,6 @@ func (r *rpcClient) newCodec(contentType string) (codec.NewCodec, error) {
|
|||||||
|
|
||||||
func (r *rpcClient) call(ctx context.Context, node *registry.Node, req Request, resp interface{}, opts CallOptions) error {
|
func (r *rpcClient) call(ctx context.Context, node *registry.Node, req Request, resp interface{}, opts CallOptions) error {
|
||||||
address := node.Address
|
address := node.Address
|
||||||
if node.Port > 0 {
|
|
||||||
address = fmt.Sprintf("%s:%d", address, node.Port)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := &transport.Message{
|
msg := &transport.Message{
|
||||||
Header: make(map[string]string),
|
Header: make(map[string]string),
|
||||||
@ -160,9 +155,6 @@ func (r *rpcClient) call(ctx context.Context, node *registry.Node, req Request,
|
|||||||
|
|
||||||
func (r *rpcClient) stream(ctx context.Context, node *registry.Node, req Request, opts CallOptions) (Stream, error) {
|
func (r *rpcClient) stream(ctx context.Context, node *registry.Node, req Request, opts CallOptions) (Stream, error) {
|
||||||
address := node.Address
|
address := node.Address
|
||||||
if node.Port > 0 {
|
|
||||||
address = fmt.Sprintf("%s:%d", address, node.Port)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := &transport.Message{
|
msg := &transport.Message{
|
||||||
Header: make(map[string]string),
|
Header: make(map[string]string),
|
||||||
@ -290,19 +282,9 @@ func (r *rpcClient) next(request Request, opts CallOptions) (selector.Next, erro
|
|||||||
if len(opts.Address) > 0 {
|
if len(opts.Address) > 0 {
|
||||||
var nodes []*registry.Node
|
var nodes []*registry.Node
|
||||||
|
|
||||||
for _, addr := range opts.Address {
|
for _, address := range opts.Address {
|
||||||
address := addr
|
|
||||||
port := 0
|
|
||||||
|
|
||||||
host, sport, err := net.SplitHostPort(addr)
|
|
||||||
if err == nil {
|
|
||||||
address = host
|
|
||||||
port, _ = strconv.Atoi(sport)
|
|
||||||
}
|
|
||||||
|
|
||||||
nodes = append(nodes, ®istry.Node{
|
nodes = append(nodes, ®istry.Node{
|
||||||
Address: address,
|
Address: address,
|
||||||
Port: port,
|
|
||||||
// Set the protocol
|
// Set the protocol
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"protocol": "mucp",
|
"protocol": "mucp",
|
||||||
|
@ -22,8 +22,7 @@ func TestCallAddress(t *testing.T) {
|
|||||||
var called bool
|
var called bool
|
||||||
service := "test.service"
|
service := "test.service"
|
||||||
endpoint := "Test.Endpoint"
|
endpoint := "Test.Endpoint"
|
||||||
address := "10.1.10.1"
|
address := "10.1.10.1:8080"
|
||||||
port := 8080
|
|
||||||
|
|
||||||
wrap := func(cf CallFunc) CallFunc {
|
wrap := func(cf CallFunc) CallFunc {
|
||||||
return func(ctx context.Context, node *registry.Node, req Request, rsp interface{}, opts CallOptions) error {
|
return func(ctx context.Context, node *registry.Node, req Request, rsp interface{}, opts CallOptions) error {
|
||||||
@ -41,10 +40,6 @@ func TestCallAddress(t *testing.T) {
|
|||||||
return fmt.Errorf("expected address: %s got %s", address, node.Address)
|
return fmt.Errorf("expected address: %s got %s", address, node.Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.Port != port {
|
|
||||||
return fmt.Errorf("expected address: %d got %d", port, node.Port)
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't do the call
|
// don't do the call
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -60,7 +55,7 @@ func TestCallAddress(t *testing.T) {
|
|||||||
req := c.NewRequest(service, endpoint, nil)
|
req := c.NewRequest(service, endpoint, nil)
|
||||||
|
|
||||||
// test calling remote address
|
// test calling remote address
|
||||||
if err := c.Call(context.Background(), req, nil, WithAddress(fmt.Sprintf("%s:%d", address, port))); err != nil {
|
if err := c.Call(context.Background(), req, nil, WithAddress(address)); err != nil {
|
||||||
t.Fatal("call with address error", err)
|
t.Fatal("call with address error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +109,7 @@ func TestCallWrapper(t *testing.T) {
|
|||||||
id := "test.1"
|
id := "test.1"
|
||||||
service := "test.service"
|
service := "test.service"
|
||||||
endpoint := "Test.Endpoint"
|
endpoint := "Test.Endpoint"
|
||||||
address := "10.1.10.1"
|
address := "10.1.10.1:8080"
|
||||||
port := 8080
|
|
||||||
|
|
||||||
wrap := func(cf CallFunc) CallFunc {
|
wrap := func(cf CallFunc) CallFunc {
|
||||||
return func(ctx context.Context, node *registry.Node, req Request, rsp interface{}, opts CallOptions) error {
|
return func(ctx context.Context, node *registry.Node, req Request, rsp interface{}, opts CallOptions) error {
|
||||||
@ -152,7 +146,6 @@ func TestCallWrapper(t *testing.T) {
|
|||||||
®istry.Node{
|
®istry.Node{
|
||||||
Id: id,
|
Id: id,
|
||||||
Address: address,
|
Address: address,
|
||||||
Port: port,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -14,13 +14,11 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-123",
|
Id: "foo-1.0.0-123",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-321",
|
Id: "foo-1.0.0-321",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -30,8 +28,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.1-321",
|
Id: "foo-1.0.1-321",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -41,8 +38,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.3-345",
|
Id: "foo-1.0.3-345",
|
||||||
Address: "localhost",
|
Address: "localhost:8888",
|
||||||
Port: 8888,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -66,8 +67,7 @@ func (d *dnsSelector) Select(service string, opts ...selector.SelectOption) (sel
|
|||||||
for _, node := range srv {
|
for _, node := range srv {
|
||||||
nodes = append(nodes, ®istry.Node{
|
nodes = append(nodes, ®istry.Node{
|
||||||
Id: node.Target,
|
Id: node.Target,
|
||||||
Address: node.Target,
|
Address: fmt.Sprintf("%s:%d", node.Target, node.Port),
|
||||||
Port: int(node.Port),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,8 @@ package router
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/micro/go-micro/client"
|
"github.com/micro/go-micro/client"
|
||||||
@ -67,11 +64,7 @@ func (r *routerSelector) getRoutes(service string) ([]router.Route, error) {
|
|||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
for _, node := range service.Nodes {
|
for _, node := range service.Nodes {
|
||||||
addr := node.Address
|
addrs = append(addrs, node.Address)
|
||||||
if node.Port > 0 {
|
|
||||||
addr = fmt.Sprintf("%s:%d", node.Address, node.Port)
|
|
||||||
}
|
|
||||||
addrs = append(addrs, addr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,23 +161,11 @@ func (r *routerSelector) Select(service string, opts ...selector.SelectOption) (
|
|||||||
|
|
||||||
// defaults to gateway and no port
|
// defaults to gateway and no port
|
||||||
address := route.Gateway
|
address := route.Gateway
|
||||||
port := 0
|
|
||||||
|
|
||||||
// check if its host:port
|
|
||||||
host, pr, err := net.SplitHostPort(address)
|
|
||||||
if err == nil {
|
|
||||||
pp, _ := strconv.Atoi(pr)
|
|
||||||
// set port
|
|
||||||
port = pp
|
|
||||||
// set address
|
|
||||||
address = host
|
|
||||||
}
|
|
||||||
|
|
||||||
// return as a node
|
// return as a node
|
||||||
return ®istry.Node{
|
return ®istry.Node{
|
||||||
// TODO: add id and metadata if we can
|
// TODO: add id and metadata if we can
|
||||||
Address: address,
|
Address: address,
|
||||||
Port: port,
|
|
||||||
}, nil
|
}, nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
package static
|
package static
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/micro/go-micro/client/selector"
|
"github.com/micro/go-micro/client/selector"
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
)
|
)
|
||||||
@ -26,20 +23,10 @@ func (s *staticSelector) Options() selector.Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *staticSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
|
func (s *staticSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
|
||||||
var port int
|
|
||||||
addr, pt, err := net.SplitHostPort(service)
|
|
||||||
if err != nil {
|
|
||||||
addr = service
|
|
||||||
port = 0
|
|
||||||
} else {
|
|
||||||
port, _ = strconv.Atoi(pt)
|
|
||||||
}
|
|
||||||
|
|
||||||
return func() (*registry.Node, error) {
|
return func() (*registry.Node, error) {
|
||||||
return ®istry.Node{
|
return ®istry.Node{
|
||||||
Id: service,
|
Id: service,
|
||||||
Address: addr,
|
Address: service,
|
||||||
Port: port,
|
|
||||||
}, nil
|
}, nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,11 @@ func TestStrategies(t *testing.T) {
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
®istry.Node{
|
®istry.Node{
|
||||||
Id: "test1-1",
|
Id: "test1-1",
|
||||||
Address: "10.0.0.1",
|
Address: "10.0.0.1:1001",
|
||||||
Port: 1001,
|
|
||||||
},
|
},
|
||||||
®istry.Node{
|
®istry.Node{
|
||||||
Id: "test1-2",
|
Id: "test1-2",
|
||||||
Address: "10.0.0.2",
|
Address: "10.0.0.2:1002",
|
||||||
Port: 1002,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -30,13 +28,11 @@ func TestStrategies(t *testing.T) {
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
®istry.Node{
|
®istry.Node{
|
||||||
Id: "test1-3",
|
Id: "test1-3",
|
||||||
Address: "10.0.0.3",
|
Address: "10.0.0.3:1003",
|
||||||
Port: 1003,
|
|
||||||
},
|
},
|
||||||
®istry.Node{
|
®istry.Node{
|
||||||
Id: "test1-4",
|
Id: "test1-4",
|
||||||
Address: "10.0.0.4",
|
Address: "10.0.0.4:1004",
|
||||||
Port: 1004,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -14,13 +14,11 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-123",
|
Id: "foo-1.0.0-123",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-321",
|
Id: "foo-1.0.0-321",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -30,8 +28,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.1-321",
|
Id: "foo-1.0.1-321",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -41,8 +38,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.3-345",
|
Id: "foo-1.0.3-345",
|
||||||
Address: "localhost",
|
Address: "localhost:8888",
|
||||||
Port: 8888,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -158,7 +158,7 @@ func newNode(n *network) (*node, error) {
|
|||||||
// register with the network id
|
// register with the network id
|
||||||
Name: n.Name(),
|
Name: n.Name(),
|
||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{Id: node.id, Address: addr, Port: port},
|
{Id: node.id, Address: node.address},
|
||||||
},
|
},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
node.Close()
|
node.Close()
|
||||||
|
@ -3,7 +3,6 @@ package mucp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -157,11 +156,7 @@ func (p *Proxy) getRoute(service string) ([]string, error) {
|
|||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
for _, node := range service.Nodes {
|
for _, node := range service.Nodes {
|
||||||
addr := node.Address
|
addrs = append(addrs, node.Address)
|
||||||
if node.Port > 0 {
|
|
||||||
addr = fmt.Sprintf("%s:%d", node.Address, node.Port)
|
|
||||||
}
|
|
||||||
addrs = append(addrs, addr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
package registry
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/micro/go-micro/network/resolver"
|
"github.com/micro/go-micro/network/resolver"
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
)
|
)
|
||||||
@ -29,13 +27,8 @@ func (r *Resolver) Resolve(id string) ([]*resolver.Record, error) {
|
|||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
for _, node := range service.Nodes {
|
for _, node := range service.Nodes {
|
||||||
addr := node.Address
|
|
||||||
// such a hack
|
|
||||||
if node.Port > 0 {
|
|
||||||
addr = fmt.Sprintf("%s:%d", node.Address, node.Port)
|
|
||||||
}
|
|
||||||
records = append(records, &resolver.Record{
|
records = append(records, &resolver.Record{
|
||||||
Address: addr,
|
Address: node.Address,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,13 +98,9 @@ func (r *router) addServiceRoutes(reg registry.Registry, network string, metric
|
|||||||
|
|
||||||
// range over the flat slice of nodes
|
// range over the flat slice of nodes
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
gateway := node.Address
|
|
||||||
if node.Port > 0 {
|
|
||||||
gateway = fmt.Sprintf("%s:%d", node.Address, node.Port)
|
|
||||||
}
|
|
||||||
route := Route{
|
route := Route{
|
||||||
Destination: service.Name,
|
Destination: service.Name,
|
||||||
Gateway: gateway,
|
Gateway: node.Address,
|
||||||
Router: r.opts.Address,
|
Router: r.opts.Address,
|
||||||
Network: r.opts.Network,
|
Network: r.opts.Network,
|
||||||
Metric: metric,
|
Metric: metric,
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -220,7 +221,7 @@ func (c *consulRegistry) Register(s *registry.Service, opts ...registry.Register
|
|||||||
deregTTL := getDeregisterTTL(regInterval)
|
deregTTL := getDeregisterTTL(regInterval)
|
||||||
|
|
||||||
check = &consul.AgentServiceCheck{
|
check = &consul.AgentServiceCheck{
|
||||||
TCP: fmt.Sprintf("%s:%d", node.Address, node.Port),
|
TCP: node.Address,
|
||||||
Interval: fmt.Sprintf("%v", regInterval),
|
Interval: fmt.Sprintf("%v", regInterval),
|
||||||
DeregisterCriticalServiceAfter: fmt.Sprintf("%v", deregTTL),
|
DeregisterCriticalServiceAfter: fmt.Sprintf("%v", deregTTL),
|
||||||
}
|
}
|
||||||
@ -235,13 +236,16 @@ func (c *consulRegistry) Register(s *registry.Service, opts ...registry.Register
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host, pt, _ := net.SplitHostPort(node.Address)
|
||||||
|
port, _ := strconv.Atoi(pt)
|
||||||
|
|
||||||
// register the service
|
// register the service
|
||||||
asr := &consul.AgentServiceRegistration{
|
asr := &consul.AgentServiceRegistration{
|
||||||
ID: node.Id,
|
ID: node.Id,
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Port: node.Port,
|
Port: port,
|
||||||
Address: node.Address,
|
Address: host,
|
||||||
Check: check,
|
Check: check,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,8 +338,7 @@ func (c *consulRegistry) GetService(name string) ([]*registry.Service, error) {
|
|||||||
|
|
||||||
svc.Nodes = append(svc.Nodes, ®istry.Node{
|
svc.Nodes = append(svc.Nodes, ®istry.Node{
|
||||||
Id: id,
|
Id: id,
|
||||||
Address: address,
|
Address: fmt.Sprintf("%s:%d", address, s.Service.Port),
|
||||||
Port: s.Service.Port,
|
|
||||||
Metadata: decodeMetadata(s.Service.Tags),
|
Metadata: decodeMetadata(s.Service.Tags),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package consul
|
package consul
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
@ -102,8 +103,7 @@ func (cw *consulWatcher) serviceHandler(idx uint64, data interface{}) {
|
|||||||
|
|
||||||
svc.Nodes = append(svc.Nodes, ®istry.Node{
|
svc.Nodes = append(svc.Nodes, ®istry.Node{
|
||||||
Id: id,
|
Id: id,
|
||||||
Address: address,
|
Address: fmt.Sprintf("%s:%d", address, e.Service.Port),
|
||||||
Port: e.Service.Port,
|
|
||||||
Metadata: decodeMetadata(e.Service.Tags),
|
Metadata: decodeMetadata(e.Service.Tags),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ package registry
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -127,14 +129,22 @@ func (m *mdnsRegistry) Register(service *Service, opts ...RegisterOption) error
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
host, pt, err := net.SplitHostPort(node.Address)
|
||||||
|
if err != nil {
|
||||||
|
gerr = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
port, _ := strconv.Atoi(pt)
|
||||||
|
|
||||||
// we got here, new node
|
// we got here, new node
|
||||||
s, err := mdns.NewMDNSService(
|
s, err := mdns.NewMDNSService(
|
||||||
node.Id,
|
node.Id,
|
||||||
service.Name,
|
service.Name,
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
node.Port,
|
port,
|
||||||
[]net.IP{net.ParseIP(node.Address)},
|
[]net.IP{net.ParseIP(host)},
|
||||||
txt,
|
txt,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -238,8 +248,7 @@ func (m *mdnsRegistry) GetService(service string) ([]*Service, error) {
|
|||||||
|
|
||||||
s.Nodes = append(s.Nodes, &Node{
|
s.Nodes = append(s.Nodes, &Node{
|
||||||
Id: strings.TrimSuffix(e.Name, "."+p.Service+"."+p.Domain+"."),
|
Id: strings.TrimSuffix(e.Name, "."+p.Service+"."+p.Domain+"."),
|
||||||
Address: e.AddrV4.String(),
|
Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port),
|
||||||
Port: e.Port,
|
|
||||||
Metadata: txt.Metadata,
|
Metadata: txt.Metadata,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -13,8 +13,7 @@ func TestMDNS(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
&Node{
|
&Node{
|
||||||
Id: "test1-1",
|
Id: "test1-1",
|
||||||
Address: "10.0.0.1",
|
Address: "10.0.0.1:10001",
|
||||||
Port: 10001,
|
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
@ -27,8 +26,7 @@ func TestMDNS(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
&Node{
|
&Node{
|
||||||
Id: "test2-1",
|
Id: "test2-1",
|
||||||
Address: "10.0.0.2",
|
Address: "10.0.0.2:10002",
|
||||||
Port: 10002,
|
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"foo2": "bar2",
|
"foo2": "bar2",
|
||||||
},
|
},
|
||||||
@ -41,8 +39,7 @@ func TestMDNS(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
&Node{
|
&Node{
|
||||||
Id: "test3-1",
|
Id: "test3-1",
|
||||||
Address: "10.0.0.3",
|
Address: "10.0.0.3:10003",
|
||||||
Port: 10003,
|
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"foo3": "bar3",
|
"foo3": "bar3",
|
||||||
},
|
},
|
||||||
@ -92,10 +89,6 @@ func TestMDNS(t *testing.T) {
|
|||||||
if node.Address != service.Nodes[0].Address {
|
if node.Address != service.Nodes[0].Address {
|
||||||
t.Fatalf("Expected node address %s got %s", service.Nodes[0].Address, node.Address)
|
t.Fatalf("Expected node address %s got %s", service.Nodes[0].Address, node.Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.Port != service.Nodes[0].Port {
|
|
||||||
t.Fatalf("Expected node port %d got %d", service.Nodes[0].Port, node.Port)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
services, err := r.ListServices()
|
services, err := r.ListServices()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package registry
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/micro/mdns"
|
"github.com/micro/mdns"
|
||||||
@ -52,8 +53,7 @@ func (m *mdnsWatcher) Next() (*Result, error) {
|
|||||||
|
|
||||||
service.Nodes = append(service.Nodes, &Node{
|
service.Nodes = append(service.Nodes, &Node{
|
||||||
Id: strings.TrimSuffix(e.Name, "."+service.Name+".local."),
|
Id: strings.TrimSuffix(e.Name, "."+service.Name+".local."),
|
||||||
Address: e.AddrV4.String(),
|
Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port),
|
||||||
Port: e.Port,
|
|
||||||
Metadata: txt.Metadata,
|
Metadata: txt.Metadata,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -15,13 +15,11 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-123",
|
Id: "foo-1.0.0-123",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.0-321",
|
Id: "foo-1.0.0-321",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -31,8 +29,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.1-321",
|
Id: "foo-1.0.1-321",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -42,8 +39,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "foo-1.0.3-345",
|
Id: "foo-1.0.3-345",
|
||||||
Address: "localhost",
|
Address: "localhost:8888",
|
||||||
Port: 8888,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -55,13 +51,11 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "bar-1.0.0-123",
|
Id: "bar-1.0.0-123",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: "bar-1.0.0-321",
|
Id: "bar-1.0.0-321",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -71,8 +65,7 @@ var (
|
|||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "bar-1.0.1-321",
|
Id: "bar-1.0.1-321",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,6 @@ type Service struct {
|
|||||||
type Node struct {
|
type Node struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
Port int `json:"port"`
|
|
||||||
Metadata map[string]string `json:"metadata"`
|
Metadata map[string]string `json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,7 @@ func TestRemove(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
{
|
{
|
||||||
Id: "foo-123",
|
Id: "foo-123",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -23,8 +22,7 @@ func TestRemove(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
{
|
{
|
||||||
Id: "foo-123",
|
Id: "foo-123",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -45,13 +43,11 @@ func TestRemoveNodes(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
{
|
{
|
||||||
Id: "foo-123",
|
Id: "foo-123",
|
||||||
Address: "localhost",
|
Address: "localhost:9999",
|
||||||
Port: 9999,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: "foo-321",
|
Id: "foo-321",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -61,8 +57,7 @@ func TestRemoveNodes(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
{
|
{
|
||||||
Id: "foo-123",
|
Id: "foo-123",
|
||||||
Address: "localhost",
|
Address: "localhost:6666",
|
||||||
Port: 6666,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -12,8 +12,7 @@ func TestWatcher(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
&Node{
|
&Node{
|
||||||
Id: "test1-1",
|
Id: "test1-1",
|
||||||
Address: "10.0.0.1",
|
Address: "10.0.0.1:10001",
|
||||||
Port: 10001,
|
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
@ -26,8 +25,7 @@ func TestWatcher(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
&Node{
|
&Node{
|
||||||
Id: "test2-1",
|
Id: "test2-1",
|
||||||
Address: "10.0.0.2",
|
Address: "10.0.0.2:10002",
|
||||||
Port: 10002,
|
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"foo2": "bar2",
|
"foo2": "bar2",
|
||||||
},
|
},
|
||||||
@ -40,8 +38,7 @@ func TestWatcher(t *testing.T) {
|
|||||||
Nodes: []*Node{
|
Nodes: []*Node{
|
||||||
&Node{
|
&Node{
|
||||||
Id: "test3-1",
|
Id: "test3-1",
|
||||||
Address: "10.0.0.3",
|
Address: "10.0.0.3:10003",
|
||||||
Port: 10003,
|
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"foo3": "bar3",
|
"foo3": "bar3",
|
||||||
},
|
},
|
||||||
@ -77,10 +74,6 @@ func TestWatcher(t *testing.T) {
|
|||||||
if node.Address != service.Nodes[0].Address {
|
if node.Address != service.Nodes[0].Address {
|
||||||
t.Fatalf("Expected node address %s got %s", service.Nodes[0].Address, node.Address)
|
t.Fatalf("Expected node address %s got %s", service.Nodes[0].Address, node.Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.Port != service.Nodes[0].Port {
|
|
||||||
t.Fatalf("Expected node port %d got %d", service.Nodes[0].Port, node.Port)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// new registry
|
// new registry
|
||||||
|
@ -534,8 +534,7 @@ func (g *grpcServer) Register() error {
|
|||||||
// register service
|
// register service
|
||||||
node := ®istry.Node{
|
node := ®istry.Node{
|
||||||
Id: config.Name + "-" + config.Id,
|
Id: config.Name + "-" + config.Id,
|
||||||
Address: addr,
|
Address: fmt.Sprintf("%s:%d", addr, port),
|
||||||
Port: port,
|
|
||||||
Metadata: config.Metadata,
|
Metadata: config.Metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,8 +657,7 @@ func (g *grpcServer) Deregister() error {
|
|||||||
|
|
||||||
node := ®istry.Node{
|
node := ®istry.Node{
|
||||||
Id: config.Name + "-" + config.Id,
|
Id: config.Name + "-" + config.Id,
|
||||||
Address: addr,
|
Address: fmt.Sprintf("%s:%d", addr, port),
|
||||||
Port: port,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
service := ®istry.Service{
|
service := ®istry.Service{
|
||||||
|
@ -313,8 +313,7 @@ func (s *rpcServer) Register() error {
|
|||||||
// register service
|
// register service
|
||||||
node := ®istry.Node{
|
node := ®istry.Node{
|
||||||
Id: config.Name + "-" + config.Id,
|
Id: config.Name + "-" + config.Id,
|
||||||
Address: addr,
|
Address: fmt.Sprintf("%s:%d", addr, port),
|
||||||
Port: port,
|
|
||||||
Metadata: md,
|
Metadata: md,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,8 +440,7 @@ func (s *rpcServer) Deregister() error {
|
|||||||
|
|
||||||
node := ®istry.Node{
|
node := ®istry.Node{
|
||||||
Id: config.Name + "-" + config.Id,
|
Id: config.Name + "-" + config.Id,
|
||||||
Address: addr,
|
Address: fmt.Sprintf("%s:%d", addr, port),
|
||||||
Port: port,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
service := ®istry.Service{
|
service := ®istry.Service{
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
@ -30,16 +29,12 @@ func TestRoundTripper(t *testing.T) {
|
|||||||
|
|
||||||
go http.Serve(l, nil)
|
go http.Serve(l, nil)
|
||||||
|
|
||||||
host, p, _ := net.SplitHostPort(l.Addr().String())
|
|
||||||
port, _ := strconv.Atoi(p)
|
|
||||||
|
|
||||||
m.Register(®istry.Service{
|
m.Register(®istry.Service{
|
||||||
Name: "example.com",
|
Name: "example.com",
|
||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "1",
|
Id: "1",
|
||||||
Address: host,
|
Address: l.Addr().String(),
|
||||||
Port: port,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -2,7 +2,6 @@ package http
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/micro/go-micro/client/selector"
|
"github.com/micro/go-micro/client/selector"
|
||||||
@ -28,7 +27,7 @@ func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
req.URL.Host = fmt.Sprintf("%s:%d", n.Address, n.Port)
|
req.URL.Host = n.Address
|
||||||
w, err := r.rt.RoundTrip(req)
|
w, err := r.rt.RoundTrip(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
@ -2,6 +2,7 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -83,8 +84,7 @@ func (s *service) genSrv() *registry.Service {
|
|||||||
Version: s.opts.Version,
|
Version: s.opts.Version,
|
||||||
Nodes: []*registry.Node{®istry.Node{
|
Nodes: []*registry.Node{®istry.Node{
|
||||||
Id: s.opts.Id,
|
Id: s.opts.Id,
|
||||||
Address: addr,
|
Address: fmt.Sprintf("%s:%d", addr, port),
|
||||||
Port: port,
|
|
||||||
Metadata: s.opts.Metadata,
|
Metadata: s.opts.Metadata,
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ func TestService(t *testing.T) {
|
|||||||
t.Fatalf("Expected %d but got %d services", want, have)
|
t.Fatalf("Expected %d but got %d services", want, have)
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp, err := http.Get(fmt.Sprintf("http://%s:%d", s[0].Nodes[0].Address, s[0].Nodes[0].Port))
|
rsp, err := http.Get(fmt.Sprintf("http://%s", s[0].Nodes[0].Address))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ func TestTLS(t *testing.T) {
|
|||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
}
|
}
|
||||||
client := &http.Client{Transport: tr}
|
client := &http.Client{Transport: tr}
|
||||||
rsp, err := client.Get(fmt.Sprintf("https://%s:%d", s[0].Nodes[0].Address, s[0].Nodes[0].Port))
|
rsp, err := client.Get(fmt.Sprintf("https://%s", s[0].Nodes[0].Address))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user