1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

Merge pull request #571 from micro/remove-port

Remove Port from registry
This commit is contained in:
Asim Aslam 2019-07-08 08:18:26 +01:00 committed by GitHub
commit d3edad474e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 92 additions and 228 deletions

View File

@ -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 {

View File

@ -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 := &registry.Service{
Name: service,
Nodes: []*registry.Node{
&registry.Node{
Id: service + "-1",
Address: host,
Port: port,
Address: l.Addr().String(),
},
},
}

View File

@ -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

View File

@ -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",
},
},
},

View File

@ -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 := &registry.Node{
Id: id,
Address: addr,
Port: port,
Address: fmt.Sprintf("%s:%d", addr, port),
Metadata: map[string]string{
"secure": fmt.Sprintf("%t", secure),
},

View File

@ -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",
},
},
},

View File

@ -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 {

View File

@ -2,6 +2,7 @@ package grpc
import (
"context"
"fmt"
"net"
"strconv"
"strings"
@ -50,8 +51,7 @@ func TestGRPCClient(t *testing.T) {
Nodes: []*registry.Node{
&registry.Node{
Id: "test-1",
Address: addr,
Port: port,
Address: fmt.Sprintf("%s:%d", addr, port),
},
},
})

View File

@ -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, &registry.Node{
Address: address,
Port: port,
// Set the protocol
Metadata: map[string]string{
"protocol": "mucp",

View File

@ -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) {
&registry.Node{
Id: id,
Address: address,
Port: port,
},
},
})

View File

@ -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",
},
},
},

View File

@ -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, &registry.Node{
Id: node.Target,
Address: node.Target,
Port: int(node.Port),
Address: fmt.Sprintf("%s:%d", node.Target, node.Port),
})
}

View File

@ -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 &registry.Node{
// TODO: add id and metadata if we can
Address: address,
Port: port,
}, nil
}, nil
}

View File

@ -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 &registry.Node{
Id: service,
Address: addr,
Port: port,
Address: service,
}, nil
}, nil
}

View File

@ -14,13 +14,11 @@ func TestStrategies(t *testing.T) {
Nodes: []*registry.Node{
&registry.Node{
Id: "test1-1",
Address: "10.0.0.1",
Port: 1001,
Address: "10.0.0.1:1001",
},
&registry.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{
&registry.Node{
Id: "test1-3",
Address: "10.0.0.3",
Port: 1003,
Address: "10.0.0.3:1003",
},
&registry.Node{
Id: "test1-4",
Address: "10.0.0.4",
Port: 1004,
Address: "10.0.0.4:1004",
},
},
},

View File

@ -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",
},
},
},

View File

@ -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()

View File

@ -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)
}
}
}

View File

@ -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,
})
}
}

View File

@ -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,

View File

@ -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, &registry.Node{
Id: id,
Address: address,
Port: s.Service.Port,
Address: fmt.Sprintf("%s:%d", address, s.Service.Port),
Metadata: decodeMetadata(s.Service.Tags),
})
}

View File

@ -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, &registry.Node{
Id: id,
Address: address,
Port: e.Service.Port,
Address: fmt.Sprintf("%s:%d", address, e.Service.Port),
Metadata: decodeMetadata(e.Service.Tags),
})
}

View File

@ -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,
})

View File

@ -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()

View File

@ -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,
})

View File

@ -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",
},
},
},

View File

@ -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"`
}

View File

@ -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",
},
},
},

View File

@ -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

View File

@ -534,8 +534,7 @@ func (g *grpcServer) Register() error {
// register service
node := &registry.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 := &registry.Node{
Id: config.Name + "-" + config.Id,
Address: addr,
Port: port,
Address: fmt.Sprintf("%s:%d", addr, port),
}
service := &registry.Service{

View File

@ -313,8 +313,7 @@ func (s *rpcServer) Register() error {
// register service
node := &registry.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 := &registry.Node{
Id: config.Name + "-" + config.Id,
Address: addr,
Port: port,
Address: fmt.Sprintf("%s:%d", addr, port),
}
service := &registry.Service{

View File

@ -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(&registry.Service{
Name: "example.com",
Nodes: []*registry.Node{
{
Id: "1",
Address: host,
Port: port,
Address: l.Addr().String(),
},
},
})

View File

@ -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

View File

@ -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{&registry.Node{
Id: s.opts.Id,
Address: addr,
Port: port,
Address: fmt.Sprintf("%s:%d", addr, port),
Metadata: s.opts.Metadata,
}},
}

View File

@ -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)
}