diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-11-09 11:13:53 +0900 |
---|---|---|
committer | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-11-13 11:20:07 +0900 |
commit | 9f330e66090827ce0f4e70906640e0ed76df2624 (patch) | |
tree | f98d7f338dc5209e5b5240c9395755160090a666 | |
parent | e984c6902d1a494d2354caf622891258c1f85c17 (diff) |
api/grpc_server: Use make() for an empty slice declaration
To improve code inspection result, this patch uses make() for an empty
slice declaration instead of using empty literal initializer.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | api/grpc_server.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index 5b10b055..4567f715 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -348,11 +348,12 @@ func (s *Server) GetNeighbor(ctx context.Context, arg *GetNeighborRequest) (*Get if arg == nil { return nil, fmt.Errorf("invalid request") } - p := []*Peer{} - for _, e := range s.bgpServer.GetNeighbor(arg.Address, arg.EnableAdvertised) { - p = append(p, NewPeerFromConfigStruct(e)) + neighbors := s.bgpServer.GetNeighbor(arg.Address, arg.EnableAdvertised) + peers := make([]*Peer, 0, len(neighbors)) + for _, e := range neighbors { + peers = append(peers, NewPeerFromConfigStruct(e)) } - return &GetNeighborResponse{Peers: p}, nil + return &GetNeighborResponse{Peers: peers}, nil } func NewValidationFromTableStruct(v *table.Validation) *RPKIValidation { @@ -449,8 +450,9 @@ func (s *Server) GetRib(ctx context.Context, arg *GetRibRequest) (*GetRibRespons return nil, err } - dsts := []*Destination{} - for _, dst := range tbl.GetDestinations() { + tblDsts := tbl.GetDestinations() + dsts := make([]*Destination, 0, len(tblDsts)) + for _, dst := range tblDsts { dsts = append(dsts, &Destination{ Prefix: dst.GetNlri().String(), Paths: func(paths []*table.Path) []*Path { @@ -941,7 +943,7 @@ func (s *Server) GetRoa(ctx context.Context, arg *GetRoaRequest) (*GetRoaRespons } func (s *Server) EnableZebra(ctx context.Context, arg *EnableZebraRequest) (*EnableZebraResponse, error) { - l := []config.InstallProtocolType{} + l := make([]config.InstallProtocolType, 0, len(arg.RouteTypes)) for _, p := range arg.RouteTypes { if err := config.InstallProtocolType(p).Validate(); err != nil { return &EnableZebraResponse{}, err |