Skip to content

Commit

Permalink
self code review
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed Apr 1, 2020
1 parent 8f262c8 commit 1d5588c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/networkservice/core/next/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ClientChainer func(...networkservice.NetworkServiceClient) networkservice.N

// NewWrappedNetworkServiceClient chains together clients with wrapper wrapped around each one
func NewWrappedNetworkServiceClient(wrapper ClientWrapper, clients ...networkservice.NetworkServiceClient) networkservice.NetworkServiceClient {
rv := &nextClient{}
rv := &nextClient{clients: make([]networkservice.NetworkServiceClient, 0, len(clients))}
for _, c := range clients {
rv.clients = append(rv.clients, wrapper(c))
}
Expand All @@ -59,7 +59,7 @@ func NewNetworkServiceClient(clients ...networkservice.NetworkServiceClient) net
}

func (n *nextClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
if n.index == 0 {
if n.index == 0 && ctx != nil {
if nextParent := Client(ctx); nextParent != nil {
n.nextParent = nextParent
}
Expand All @@ -71,7 +71,7 @@ func (n *nextClient) Request(ctx context.Context, request *networkservice.Networ
}

func (n *nextClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) {
if n.index == 0 {
if n.index == 0 && ctx != nil {
if nextParent := Client(ctx); nextParent != nil {
n.nextParent = nextParent
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/networkservice/core/next/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ func withNextServer(parent context.Context, next networkservice.NetworkServiceSe
// Server -
// Returns the Server networkservice.NetworkServiceServer to be called in the chain from the context.Context
func Server(ctx context.Context) networkservice.NetworkServiceServer {
if ctx == nil {
return nil
}
rv, ok := ctx.Value(nextServerKey).(networkservice.NetworkServiceServer)
if !ok {
client, ok := ctx.Value(nextClientKey).(networkservice.NetworkServiceClient)
Expand All @@ -77,9 +74,6 @@ func withNextClient(parent context.Context, next networkservice.NetworkServiceCl
// Client -
// Returns the Client networkservice.NetworkServiceClient to be called in the chain from the context.Context
func Client(ctx context.Context) networkservice.NetworkServiceClient {
if ctx == nil {
return nil
}
rv, ok := ctx.Value(nextClientKey).(networkservice.NetworkServiceClient)
if !ok {
server, ok := ctx.Value(nextServerKey).(networkservice.NetworkServiceServer)
Expand Down
6 changes: 3 additions & 3 deletions pkg/networkservice/core/next/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ServerChainer func(...networkservice.NetworkServiceServer) networkservice.N

// NewWrappedNetworkServiceServer - chains together the servers provides with the wrapper wrapped around each one in turn.
func NewWrappedNetworkServiceServer(wrapper ServerWrapper, servers ...networkservice.NetworkServiceServer) networkservice.NetworkServiceServer {
rv := &nextServer{}
rv := &nextServer{servers: make([]networkservice.NetworkServiceServer, 0, len(servers))}
for _, s := range servers {
rv.servers = append(rv.servers, wrapper(s))
}
Expand All @@ -59,7 +59,7 @@ func NewNetworkServiceServer(servers ...networkservice.NetworkServiceServer) net
}

func (n *nextServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
if n.index == 0 {
if n.index == 0 && ctx != nil {
if nextParent := Server(ctx); nextParent != nil {
n.nextParent = nextParent
}
Expand All @@ -71,7 +71,7 @@ func (n *nextServer) Request(ctx context.Context, request *networkservice.Networ
}

func (n *nextServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) {
if n.index == 0 {
if n.index == 0 && ctx != nil {
if nextParent := Server(ctx); nextParent != nil {
n.nextParent = nextParent
}
Expand Down

0 comments on commit 1d5588c

Please sign in to comment.