Fix breaks related to removing node.port
This commit is contained in:
parent
214a98c3d2
commit
aa101624c2
13
http.go
13
http.go
@ -57,10 +57,6 @@ func (h *httpClient) next(request client.Request, opts client.CallOptions) (sele
|
|||||||
func (h *httpClient) call(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
func (h *httpClient) call(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
||||||
// set the address
|
// set the address
|
||||||
address := node.Address
|
address := node.Address
|
||||||
if node.Port > 0 {
|
|
||||||
address = fmt.Sprintf("%s:%d", address, node.Port)
|
|
||||||
}
|
|
||||||
|
|
||||||
header := make(http.Header)
|
header := make(http.Header)
|
||||||
if md, ok := metadata.FromContext(ctx); ok {
|
if md, ok := metadata.FromContext(ctx); ok {
|
||||||
for k, v := range md {
|
for k, v := range md {
|
||||||
@ -125,10 +121,6 @@ func (h *httpClient) call(ctx context.Context, node *registry.Node, req client.R
|
|||||||
func (h *httpClient) stream(ctx context.Context, node *registry.Node, req client.Request, opts client.CallOptions) (client.Stream, error) {
|
func (h *httpClient) stream(ctx context.Context, node *registry.Node, req client.Request, opts client.CallOptions) (client.Stream, error) {
|
||||||
// set the address
|
// set the address
|
||||||
address := node.Address
|
address := node.Address
|
||||||
if node.Port > 0 {
|
|
||||||
address = fmt.Sprintf("%s:%d", address, node.Port)
|
|
||||||
}
|
|
||||||
|
|
||||||
header := make(http.Header)
|
header := make(http.Header)
|
||||||
if md, ok := metadata.FromContext(ctx); ok {
|
if md, ok := metadata.FromContext(ctx); ok {
|
||||||
for k, v := range md {
|
for k, v := range md {
|
||||||
@ -351,11 +343,6 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := node.Address
|
|
||||||
if node.Port > 0 {
|
|
||||||
addr = fmt.Sprintf("%s:%d", addr, node.Port)
|
|
||||||
}
|
|
||||||
|
|
||||||
stream, err := h.stream(ctx, node, req, callOpts)
|
stream, err := h.stream(ctx, node, req, callOpts)
|
||||||
h.opts.Selector.Mark(req.Service(), node, err)
|
h.opts.Selector.Mark(req.Service(), node, err)
|
||||||
return stream, err
|
return stream, err
|
||||||
|
19
http_test.go
19
http_test.go
@ -8,7 +8,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/micro/go-micro/client"
|
"github.com/micro/go-micro/client"
|
||||||
@ -68,19 +67,12 @@ func TestHTTPClient(t *testing.T) {
|
|||||||
})
|
})
|
||||||
go http.Serve(l, mux)
|
go http.Serve(l, mux)
|
||||||
|
|
||||||
host, sport, err := net.SplitHostPort(l.Addr().String())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
port, _ := strconv.Atoi(sport)
|
|
||||||
|
|
||||||
if err := r.Register(®istry.Service{
|
if err := r.Register(®istry.Service{
|
||||||
Name: "test.service",
|
Name: "test.service",
|
||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "test.service.1",
|
Id: "test.service.1",
|
||||||
Address: host,
|
Address: l.Addr().String(),
|
||||||
Port: port,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -231,19 +223,12 @@ func TestHTTPClientStream(t *testing.T) {
|
|||||||
})
|
})
|
||||||
go http.Serve(l, mux)
|
go http.Serve(l, mux)
|
||||||
|
|
||||||
host, sport, err := net.SplitHostPort(l.Addr().String())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
port, _ := strconv.Atoi(sport)
|
|
||||||
|
|
||||||
if err := r.Register(®istry.Service{
|
if err := r.Register(®istry.Service{
|
||||||
Name: "test.service",
|
Name: "test.service",
|
||||||
Nodes: []*registry.Node{
|
Nodes: []*registry.Node{
|
||||||
{
|
{
|
||||||
Id: "test.service.1",
|
Id: "test.service.1",
|
||||||
Address: host,
|
Address: l.Addr().String(),
|
||||||
Port: port,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user