Canonical guidance

Use when

Avoid

Preferred pattern

type UserService struct {
	pb.UnimplementedUserServiceServer
	Store Store
}

func (s *UserService) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.GetUserResponse, error) {
	user, err := s.Store.Get(ctx, req.Id)
	if err != nil {
		return nil, err
	}
	return &pb.GetUserResponse{Id: user.ID, Name: user.Name}, nil
}

Anti-pattern

Explanation: This anti-pattern is tempting because gRPC stubs are already there, but it turns transport code into the whole application boundary.

Why

Related pages

Sources