When using the Go implementation of GRPC, what is considered best practice in regards to reusing or sharing empty or unchanging responses between multiple requests? This saves an unnecessary allocation - but is there any reason not to?
For example:
var emptyPingResponse = &pb.PingResponse{}
var staticBuildInfo = &pb.GetBuildInfoResponse {
Version: /* ... */,
BuildDate: /* ... */,
}
func (*Service) Ping(ctx context.Context, req *pb.PingRequest) (res *pb.PingResponse, err error) {
// do something here
return emptyPingResponse, nil
}
func (*Service) GetBuildInfo(ctx context.Context, req *pb.GetBuildInfoRequest) (res *pb.GetBuildInfoResponse, err error) {
return staticBuildInfo, nil
}