diff --git a/api/handler/http/http.go b/api/handler/http/http.go index b9380ce3..ad2b1c66 100644 --- a/api/handler/http/http.go +++ b/api/handler/http/http.go @@ -73,7 +73,7 @@ func (h *httpHandler) getService(r *http.Request) (string, error) { 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 { diff --git a/api/handler/http/http_test.go b/api/handler/http/http_test.go index 78c135b6..31847221 100644 --- a/api/handler/http/http_test.go +++ b/api/handler/http/http_test.go @@ -4,8 +4,6 @@ import ( "net" "net/http" "net/http/httptest" - "strconv" - "strings" "testing" "github.com/micro/go-micro/api/handler" @@ -26,21 +24,12 @@ func testHttp(t *testing.T, path, service, ns string) { } 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{ Name: service, Nodes: []*registry.Node{ ®istry.Node{ Id: service + "-1", - Address: host, - Port: port, + Address: l.Addr().String(), }, }, } diff --git a/api/handler/web/web.go b/api/handler/web/web.go index 415dd694..77a0f6af 100644 --- a/api/handler/web/web.go +++ b/api/handler/web/web.go @@ -79,7 +79,7 @@ func (wh *webHandler) getService(r *http.Request) (string, error) { 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 diff --git a/broker/common_test.go b/broker/common_test.go index af54db18..262a77eb 100644 --- a/broker/common_test.go +++ b/broker/common_test.go @@ -14,13 +14,11 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.0-123", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, { Id: "foo-1.0.0-321", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, }, }, @@ -30,8 +28,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.1-321", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, @@ -41,8 +38,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.3-345", - Address: "localhost", - Port: 8888, + Address: "localhost:8888", }, }, }, diff --git a/broker/http_broker.go b/broker/http_broker.go index d148da5d..d28eeb2c 100644 --- a/broker/http_broker.go +++ b/broker/http_broker.go @@ -543,7 +543,7 @@ func (h *httpBroker) Publish(topic string, msg *Message, opts ...PublishOption) vals := url.Values{} 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)) if err != nil { return err @@ -638,8 +638,7 @@ func (h *httpBroker) Subscribe(topic string, handler Handler, opts ...SubscribeO // register service node := ®istry.Node{ Id: id, - Address: addr, - Port: port, + Address: fmt.Sprintf("%s:%d", addr, port), Metadata: map[string]string{ "secure": fmt.Sprintf("%t", secure), }, diff --git a/client/common_test.go b/client/common_test.go index d172812b..15ddc158 100644 --- a/client/common_test.go +++ b/client/common_test.go @@ -14,13 +14,11 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.0-123", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, { Id: "foo-1.0.0-321", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, }, }, @@ -30,8 +28,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.1-321", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, @@ -41,8 +38,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.3-345", - Address: "localhost", - Port: 8888, + Address: "localhost:8888", }, }, }, diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 809eec2a..e79b5406 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -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 { address := node.Address - if node.Port > 0 { - address = fmt.Sprintf("%s:%d", address, node.Port) - } header := make(map[string]string) 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) { address := node.Address - if node.Port > 0 { - address = fmt.Sprintf("%s:%d", address, node.Port) - } header := make(map[string]string) if md, ok := metadata.FromContext(ctx); ok { diff --git a/client/grpc/grpc_test.go b/client/grpc/grpc_test.go index 7c58fd4e..3652ec6b 100644 --- a/client/grpc/grpc_test.go +++ b/client/grpc/grpc_test.go @@ -2,6 +2,7 @@ package grpc import ( "context" + "fmt" "net" "strconv" "strings" @@ -50,8 +51,7 @@ func TestGRPCClient(t *testing.T) { Nodes: []*registry.Node{ ®istry.Node{ Id: "test-1", - Address: addr, - Port: port, + Address: fmt.Sprintf("%s:%d", addr, port), }, }, }) diff --git a/client/rpc_client.go b/client/rpc_client.go index d2ebe74a..8f729252 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -4,9 +4,7 @@ import ( "bytes" "context" "fmt" - "net" "os" - "strconv" "sync" "sync/atomic" "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 { address := node.Address - if node.Port > 0 { - address = fmt.Sprintf("%s:%d", address, node.Port) - } msg := &transport.Message{ 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) { address := node.Address - if node.Port > 0 { - address = fmt.Sprintf("%s:%d", address, node.Port) - } msg := &transport.Message{ 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 { var nodes []*registry.Node - for _, addr := range opts.Address { - address := addr - port := 0 - - host, sport, err := net.SplitHostPort(addr) - if err == nil { - address = host - port, _ = strconv.Atoi(sport) - } - + for _, address := range opts.Address { nodes = append(nodes, ®istry.Node{ Address: address, - Port: port, // Set the protocol Metadata: map[string]string{ "protocol": "mucp", diff --git a/client/rpc_client_test.go b/client/rpc_client_test.go index 2db3ae90..14547e9f 100644 --- a/client/rpc_client_test.go +++ b/client/rpc_client_test.go @@ -22,8 +22,7 @@ func TestCallAddress(t *testing.T) { var called bool service := "test.service" endpoint := "Test.Endpoint" - address := "10.1.10.1" - port := 8080 + address := "10.1.10.1:8080" wrap := func(cf CallFunc) CallFunc { 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) } - if node.Port != port { - return fmt.Errorf("expected address: %d got %d", port, node.Port) - } - // don't do the call return nil } @@ -60,7 +55,7 @@ func TestCallAddress(t *testing.T) { req := c.NewRequest(service, endpoint, nil) // 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) } @@ -114,8 +109,7 @@ func TestCallWrapper(t *testing.T) { id := "test.1" service := "test.service" endpoint := "Test.Endpoint" - address := "10.1.10.1" - port := 8080 + address := "10.1.10.1:8080" wrap := func(cf CallFunc) CallFunc { 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{ Id: id, Address: address, - Port: port, }, }, }) diff --git a/client/selector/common_test.go b/client/selector/common_test.go index aa8c15c7..7aba0542 100644 --- a/client/selector/common_test.go +++ b/client/selector/common_test.go @@ -14,13 +14,11 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.0-123", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, { Id: "foo-1.0.0-321", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, }, }, @@ -30,8 +28,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.1-321", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, @@ -41,8 +38,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.3-345", - Address: "localhost", - Port: 8888, + Address: "localhost:8888", }, }, }, diff --git a/client/selector/dns/dns.go b/client/selector/dns/dns.go index b1d19c95..df6c209f 100644 --- a/client/selector/dns/dns.go +++ b/client/selector/dns/dns.go @@ -2,6 +2,7 @@ package dns import ( + "fmt" "net" "strconv" @@ -66,8 +67,7 @@ func (d *dnsSelector) Select(service string, opts ...selector.SelectOption) (sel for _, node := range srv { nodes = append(nodes, ®istry.Node{ Id: node.Target, - Address: node.Target, - Port: int(node.Port), + Address: fmt.Sprintf("%s:%d", node.Target, node.Port), }) } diff --git a/client/selector/router/router.go b/client/selector/router/router.go index 452c9b89..4bcdecd1 100644 --- a/client/selector/router/router.go +++ b/client/selector/router/router.go @@ -3,11 +3,8 @@ package router import ( "context" - "fmt" - "net" "os" "sort" - "strconv" "sync" "github.com/micro/go-micro/client" @@ -67,11 +64,7 @@ func (r *routerSelector) getRoutes(service string) ([]router.Route, error) { for _, service := range services { for _, node := range service.Nodes { - addr := node.Address - if node.Port > 0 { - addr = fmt.Sprintf("%s:%d", node.Address, node.Port) - } - addrs = append(addrs, addr) + addrs = append(addrs, node.Address) } } } @@ -168,23 +161,11 @@ func (r *routerSelector) Select(service string, opts ...selector.SelectOption) ( // defaults to gateway and no port 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 ®istry.Node{ // TODO: add id and metadata if we can Address: address, - Port: port, }, nil }, nil } diff --git a/client/selector/static/static.go b/client/selector/static/static.go index c9b2fd83..9bd18f03 100644 --- a/client/selector/static/static.go +++ b/client/selector/static/static.go @@ -2,9 +2,6 @@ package static import ( - "net" - "strconv" - "github.com/micro/go-micro/client/selector" "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) { - 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 ®istry.Node{ Id: service, - Address: addr, - Port: port, + Address: service, }, nil }, nil } diff --git a/client/selector/strategy_test.go b/client/selector/strategy_test.go index 17090e73..8ea9376a 100644 --- a/client/selector/strategy_test.go +++ b/client/selector/strategy_test.go @@ -14,13 +14,11 @@ func TestStrategies(t *testing.T) { Nodes: []*registry.Node{ ®istry.Node{ Id: "test1-1", - Address: "10.0.0.1", - Port: 1001, + Address: "10.0.0.1:1001", }, ®istry.Node{ Id: "test1-2", - Address: "10.0.0.2", - Port: 1002, + Address: "10.0.0.2:1002", }, }, }, @@ -30,13 +28,11 @@ func TestStrategies(t *testing.T) { Nodes: []*registry.Node{ ®istry.Node{ Id: "test1-3", - Address: "10.0.0.3", - Port: 1003, + Address: "10.0.0.3:1003", }, ®istry.Node{ Id: "test1-4", - Address: "10.0.0.4", - Port: 1004, + Address: "10.0.0.4:1004", }, }, }, diff --git a/common_test.go b/common_test.go index 612cdb37..d4fd4bfb 100644 --- a/common_test.go +++ b/common_test.go @@ -14,13 +14,11 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.0-123", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, { Id: "foo-1.0.0-321", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, }, }, @@ -30,8 +28,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.1-321", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, @@ -41,8 +38,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.3-345", - Address: "localhost", - Port: 8888, + Address: "localhost:8888", }, }, }, diff --git a/network/node.go b/network/node.go index cb0f19ad..93372c7d 100644 --- a/network/node.go +++ b/network/node.go @@ -158,7 +158,7 @@ func newNode(n *network) (*node, error) { // register with the network id Name: n.Name(), Nodes: []*registry.Node{ - {Id: node.id, Address: addr, Port: port}, + {Id: node.id, Address: node.address}, }, }); err != nil { node.Close() diff --git a/network/proxy/mucp/mucp.go b/network/proxy/mucp/mucp.go index aeecead1..1abe976b 100644 --- a/network/proxy/mucp/mucp.go +++ b/network/proxy/mucp/mucp.go @@ -3,7 +3,6 @@ package mucp import ( "context" - "fmt" "io" "os" "strings" @@ -157,11 +156,7 @@ func (p *Proxy) getRoute(service string) ([]string, error) { for _, service := range services { for _, node := range service.Nodes { - addr := node.Address - if node.Port > 0 { - addr = fmt.Sprintf("%s:%d", node.Address, node.Port) - } - addrs = append(addrs, addr) + addrs = append(addrs, node.Address) } } } diff --git a/network/resolver/registry/registry.go b/network/resolver/registry/registry.go index 09228970..c7ef796a 100644 --- a/network/resolver/registry/registry.go +++ b/network/resolver/registry/registry.go @@ -2,8 +2,6 @@ package registry import ( - "fmt" - "github.com/micro/go-micro/network/resolver" "github.com/micro/go-micro/registry" ) @@ -29,13 +27,8 @@ func (r *Resolver) Resolve(id string) ([]*resolver.Record, error) { for _, service := range services { 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{ - Address: addr, + Address: node.Address, }) } } diff --git a/network/router/default_router.go b/network/router/default_router.go index 322402ef..9a7b933e 100644 --- a/network/router/default_router.go +++ b/network/router/default_router.go @@ -98,13 +98,9 @@ func (r *router) addServiceRoutes(reg registry.Registry, network string, metric // range over the flat slice of nodes for _, node := range nodes { - gateway := node.Address - if node.Port > 0 { - gateway = fmt.Sprintf("%s:%d", node.Address, node.Port) - } route := Route{ Destination: service.Name, - Gateway: gateway, + Gateway: node.Address, Router: r.opts.Address, Network: r.opts.Network, Metric: metric, diff --git a/registry/consul/consul.go b/registry/consul/consul.go index 89f0a2d0..9a15c826 100644 --- a/registry/consul/consul.go +++ b/registry/consul/consul.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "runtime" + "strconv" "sync" "time" @@ -220,7 +221,7 @@ func (c *consulRegistry) Register(s *registry.Service, opts ...registry.Register deregTTL := getDeregisterTTL(regInterval) check = &consul.AgentServiceCheck{ - TCP: fmt.Sprintf("%s:%d", node.Address, node.Port), + TCP: node.Address, Interval: fmt.Sprintf("%v", regInterval), 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 asr := &consul.AgentServiceRegistration{ ID: node.Id, Name: s.Name, Tags: tags, - Port: node.Port, - Address: node.Address, + Port: port, + Address: host, Check: check, } @@ -334,8 +338,7 @@ func (c *consulRegistry) GetService(name string) ([]*registry.Service, error) { svc.Nodes = append(svc.Nodes, ®istry.Node{ Id: id, - Address: address, - Port: s.Service.Port, + Address: fmt.Sprintf("%s:%d", address, s.Service.Port), Metadata: decodeMetadata(s.Service.Tags), }) } diff --git a/registry/consul/watcher.go b/registry/consul/watcher.go index 1bb9d5b7..7d843482 100644 --- a/registry/consul/watcher.go +++ b/registry/consul/watcher.go @@ -1,6 +1,7 @@ package consul import ( + "fmt" "log" "os" "sync" @@ -102,8 +103,7 @@ func (cw *consulWatcher) serviceHandler(idx uint64, data interface{}) { svc.Nodes = append(svc.Nodes, ®istry.Node{ Id: id, - Address: address, - Port: e.Service.Port, + Address: fmt.Sprintf("%s:%d", address, e.Service.Port), Metadata: decodeMetadata(e.Service.Tags), }) } diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 4a3d09ec..8e68948a 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -3,7 +3,9 @@ package registry import ( "context" + "fmt" "net" + "strconv" "strings" "sync" "time" @@ -127,14 +129,22 @@ func (m *mdnsRegistry) Register(service *Service, opts ...RegisterOption) error continue } + // + host, pt, err := net.SplitHostPort(node.Address) + if err != nil { + gerr = err + continue + } + port, _ := strconv.Atoi(pt) + // we got here, new node s, err := mdns.NewMDNSService( node.Id, service.Name, "", "", - node.Port, - []net.IP{net.ParseIP(node.Address)}, + port, + []net.IP{net.ParseIP(host)}, txt, ) if err != nil { @@ -238,8 +248,7 @@ func (m *mdnsRegistry) GetService(service string) ([]*Service, error) { s.Nodes = append(s.Nodes, &Node{ Id: strings.TrimSuffix(e.Name, "."+p.Service+"."+p.Domain+"."), - Address: e.AddrV4.String(), - Port: e.Port, + Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port), Metadata: txt.Metadata, }) diff --git a/registry/mdns_test.go b/registry/mdns_test.go index 5690fe39..e9813c69 100644 --- a/registry/mdns_test.go +++ b/registry/mdns_test.go @@ -13,8 +13,7 @@ func TestMDNS(t *testing.T) { Nodes: []*Node{ &Node{ Id: "test1-1", - Address: "10.0.0.1", - Port: 10001, + Address: "10.0.0.1:10001", Metadata: map[string]string{ "foo": "bar", }, @@ -27,8 +26,7 @@ func TestMDNS(t *testing.T) { Nodes: []*Node{ &Node{ Id: "test2-1", - Address: "10.0.0.2", - Port: 10002, + Address: "10.0.0.2:10002", Metadata: map[string]string{ "foo2": "bar2", }, @@ -41,8 +39,7 @@ func TestMDNS(t *testing.T) { Nodes: []*Node{ &Node{ Id: "test3-1", - Address: "10.0.0.3", - Port: 10003, + Address: "10.0.0.3:10003", Metadata: map[string]string{ "foo3": "bar3", }, @@ -92,10 +89,6 @@ func TestMDNS(t *testing.T) { if node.Address != service.Nodes[0].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() diff --git a/registry/mdns_watcher.go b/registry/mdns_watcher.go index bbcf90ea..e1c326ff 100644 --- a/registry/mdns_watcher.go +++ b/registry/mdns_watcher.go @@ -1,6 +1,7 @@ package registry import ( + "fmt" "strings" "github.com/micro/mdns" @@ -52,8 +53,7 @@ func (m *mdnsWatcher) Next() (*Result, error) { service.Nodes = append(service.Nodes, &Node{ Id: strings.TrimSuffix(e.Name, "."+service.Name+".local."), - Address: e.AddrV4.String(), - Port: e.Port, + Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port), Metadata: txt.Metadata, }) diff --git a/registry/memory/memory_test.go b/registry/memory/memory_test.go index 3b5cd8be..fa8b53f1 100644 --- a/registry/memory/memory_test.go +++ b/registry/memory/memory_test.go @@ -15,13 +15,11 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.0-123", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, { Id: "foo-1.0.0-321", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, }, }, @@ -31,8 +29,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.1-321", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, @@ -42,8 +39,7 @@ var ( Nodes: []*registry.Node{ { Id: "foo-1.0.3-345", - Address: "localhost", - Port: 8888, + Address: "localhost:8888", }, }, }, @@ -55,13 +51,11 @@ var ( Nodes: []*registry.Node{ { Id: "bar-1.0.0-123", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, { Id: "bar-1.0.0-321", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, }, }, @@ -71,8 +65,7 @@ var ( Nodes: []*registry.Node{ { Id: "bar-1.0.1-321", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, diff --git a/registry/service.go b/registry/service.go index 5e13a002..5259a6b6 100644 --- a/registry/service.go +++ b/registry/service.go @@ -11,7 +11,6 @@ type Service struct { type Node struct { Id string `json:"id"` Address string `json:"address"` - Port int `json:"port"` Metadata map[string]string `json:"metadata"` } diff --git a/registry/util_test.go b/registry/util_test.go index 9d14c659..75fd5133 100644 --- a/registry/util_test.go +++ b/registry/util_test.go @@ -12,8 +12,7 @@ func TestRemove(t *testing.T) { Nodes: []*Node{ { Id: "foo-123", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, }, }, @@ -23,8 +22,7 @@ func TestRemove(t *testing.T) { Nodes: []*Node{ { Id: "foo-123", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, @@ -45,13 +43,11 @@ func TestRemoveNodes(t *testing.T) { Nodes: []*Node{ { Id: "foo-123", - Address: "localhost", - Port: 9999, + Address: "localhost:9999", }, { Id: "foo-321", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, @@ -61,8 +57,7 @@ func TestRemoveNodes(t *testing.T) { Nodes: []*Node{ { Id: "foo-123", - Address: "localhost", - Port: 6666, + Address: "localhost:6666", }, }, }, diff --git a/registry/watcher_test.go b/registry/watcher_test.go index 41b606b2..94c8c275 100644 --- a/registry/watcher_test.go +++ b/registry/watcher_test.go @@ -12,8 +12,7 @@ func TestWatcher(t *testing.T) { Nodes: []*Node{ &Node{ Id: "test1-1", - Address: "10.0.0.1", - Port: 10001, + Address: "10.0.0.1:10001", Metadata: map[string]string{ "foo": "bar", }, @@ -26,8 +25,7 @@ func TestWatcher(t *testing.T) { Nodes: []*Node{ &Node{ Id: "test2-1", - Address: "10.0.0.2", - Port: 10002, + Address: "10.0.0.2:10002", Metadata: map[string]string{ "foo2": "bar2", }, @@ -40,8 +38,7 @@ func TestWatcher(t *testing.T) { Nodes: []*Node{ &Node{ Id: "test3-1", - Address: "10.0.0.3", - Port: 10003, + Address: "10.0.0.3:10003", Metadata: map[string]string{ "foo3": "bar3", }, @@ -77,10 +74,6 @@ func TestWatcher(t *testing.T) { if node.Address != service.Nodes[0].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 diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 75b8823f..8d2a2d8f 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -534,8 +534,7 @@ func (g *grpcServer) Register() error { // register service node := ®istry.Node{ Id: config.Name + "-" + config.Id, - Address: addr, - Port: port, + Address: fmt.Sprintf("%s:%d", addr, port), Metadata: config.Metadata, } @@ -658,8 +657,7 @@ func (g *grpcServer) Deregister() error { node := ®istry.Node{ Id: config.Name + "-" + config.Id, - Address: addr, - Port: port, + Address: fmt.Sprintf("%s:%d", addr, port), } service := ®istry.Service{ diff --git a/server/rpc_server.go b/server/rpc_server.go index d182ae2e..2cabb635 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -313,8 +313,7 @@ func (s *rpcServer) Register() error { // register service node := ®istry.Node{ Id: config.Name + "-" + config.Id, - Address: addr, - Port: port, + Address: fmt.Sprintf("%s:%d", addr, port), Metadata: md, } @@ -441,8 +440,7 @@ func (s *rpcServer) Deregister() error { node := ®istry.Node{ Id: config.Name + "-" + config.Id, - Address: addr, - Port: port, + Address: fmt.Sprintf("%s:%d", addr, port), } service := ®istry.Service{ diff --git a/util/http/http_test.go b/util/http/http_test.go index b7bfe370..60196038 100644 --- a/util/http/http_test.go +++ b/util/http/http_test.go @@ -4,7 +4,6 @@ import ( "io/ioutil" "net" "net/http" - "strconv" "testing" "github.com/micro/go-micro/registry" @@ -30,16 +29,12 @@ func TestRoundTripper(t *testing.T) { go http.Serve(l, nil) - host, p, _ := net.SplitHostPort(l.Addr().String()) - port, _ := strconv.Atoi(p) - m.Register(®istry.Service{ Name: "example.com", Nodes: []*registry.Node{ { Id: "1", - Address: host, - Port: port, + Address: l.Addr().String(), }, }, }) diff --git a/util/http/roundtripper.go b/util/http/roundtripper.go index af2299be..36c26b5c 100644 --- a/util/http/roundtripper.go +++ b/util/http/roundtripper.go @@ -2,7 +2,6 @@ package http import ( "errors" - "fmt" "net/http" "github.com/micro/go-micro/client/selector" @@ -28,7 +27,7 @@ func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { if err != nil { continue } - req.URL.Host = fmt.Sprintf("%s:%d", n.Address, n.Port) + req.URL.Host = n.Address w, err := r.rt.RoundTrip(req) if err != nil { continue diff --git a/web/service.go b/web/service.go index e4836472..65359a2b 100644 --- a/web/service.go +++ b/web/service.go @@ -2,6 +2,7 @@ package web import ( "crypto/tls" + "fmt" "net" "net/http" "os" @@ -83,8 +84,7 @@ func (s *service) genSrv() *registry.Service { Version: s.opts.Version, Nodes: []*registry.Node{®istry.Node{ Id: s.opts.Id, - Address: addr, - Port: port, + Address: fmt.Sprintf("%s:%d", addr, port), Metadata: s.opts.Metadata, }}, } diff --git a/web/service_test.go b/web/service_test.go index f9d5af8d..588531b8 100644 --- a/web/service_test.go +++ b/web/service_test.go @@ -75,7 +75,7 @@ func TestService(t *testing.T) { 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 { t.Fatal(err) } @@ -243,7 +243,7 @@ func TestTLS(t *testing.T) { TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } 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 { t.Fatal(err) }