Skip to content

Commit 71b8bb4

Browse files
committed
server: Remove request nil checks from gRPC handlers
Remove nil checks for request parameters in gRPC handlers, as the gRPC framework guarantees that requests are never nil for regular usage. Signed-off-by: FUJITA Tomonori <[email protected]>
1 parent e38ad7c commit 71b8bb4

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

pkg/server/grpc_server.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,6 @@ func getValidation(v map[*table.Path]*table.Validation, p *table.Path) *table.Va
282282
}
283283

284284
func (s *server) listPath(ctx context.Context, r *api.ListPathRequest, fn func(*api.Destination)) error {
285-
if r == nil {
286-
return fmt.Errorf("nil request")
287-
}
288-
289285
family := bgp.Family(0)
290286
if r.Family != nil {
291287
family = bgp.NewFamily(uint16(r.Family.Afi), uint8(r.Family.Safi))
@@ -364,10 +360,6 @@ func (s *server) ListPath(r *api.ListPathRequest, stream api.GoBgpService_ListPa
364360
}
365361

366362
func (s *server) watchEvent(ctx context.Context, r *api.WatchEventRequest, fn func(*api.WatchEventResponse, time.Time)) error {
367-
if r == nil {
368-
return status.Errorf(codes.InvalidArgument, "nil request")
369-
}
370-
371363
opts := make([]WatchOption, 0)
372364
if r.GetPeer() != nil {
373365
opts = append(opts, WatchPeer())
@@ -634,8 +626,8 @@ func api2apiutilPath(path *api.Path) (*apiutil.Path, error) {
634626
}
635627

636628
func (s *server) AddPath(ctx context.Context, r *api.AddPathRequest) (*api.AddPathResponse, error) {
637-
if r == nil || r.Path == nil {
638-
return nil, fmt.Errorf("nil request")
629+
if r.Path == nil {
630+
return nil, status.Error(codes.InvalidArgument, "path is required")
639631
}
640632
var err error
641633
var uuidBytes []byte
@@ -658,9 +650,6 @@ func (s *server) AddPath(ctx context.Context, r *api.AddPathRequest) (*api.AddPa
658650
}
659651

660652
func (s *server) DeletePath(ctx context.Context, r *api.DeletePathRequest) (*api.DeletePathResponse, error) {
661-
if r == nil {
662-
return &api.DeletePathResponse{}, fmt.Errorf("nil request")
663-
}
664653
deletePath := func(ctx context.Context, r *api.DeletePathRequest) error {
665654
var pathList []*apiutil.Path
666655
if len(r.Uuid) == 0 {

0 commit comments

Comments
 (0)