title: gRPC and HTTP 1 call on single port, with out using TLS in goLang
body: <p>I have recently started working in <b>golang</b> for a project, where I have to use gRPC for push notification on my server to connect to an Android device.
  I have created a simple multiplexer <code>mux := http.NewServeMux()</code> which is working fine with my server code:</p>
  <pre><code>  serverWeb := http.Server{
      Addr:   constants.ServerIPWeb,
      //Handler: grpcHandlerFunc(grpcServer, mux),
      Handler: mux,
  }
  
  serverWeb.ListenAndServe()
  </code></pre>
  <p>As from the examples on <a href="https://grpc.io/" rel="nofollow noreferrer">gRPC.io</a> I have also created a simple gRPC client/server as a standalone project connected to my android device, with out any <code>TLS</code> configuration and its working fine.</p>
  <pre><code>type server struct{}
  
  func (s *server) DeviceData(ctx context.Context,req *pb.GetDeviceRequest) (*pb.SetDeviceResponse, error){
      util.P(&quot;Device is: &quot;,req) // simple fmt.PrintF(a ... interface)
      return  &amp;pb.SetDeviceResponse{Message:&quot;Success&quot;}, nil
  }
  
  func main(){
      lis, err := net.Listen(&quot;tcp&quot;, &quot;:8080&quot;)
      if err!=nil{
      log.Fatalf(&quot;Failed to listen: %v&quot;, err)
      }
      s := grpc.NewServer()
      pb.RegisterDeviceInfoServer(s,&amp;server{})
      reflection.Register(s)
      if err := s.Serve(lis); err != nil{
          log.Fatalf(&quot;Falied to server: %v&quot;, err)
      }
  }
  </code></pre>
  <p>The <b>problem</b> is I could not connect my current gRPC server to my serverStruct above. I have tried to add <code>Handler: grpcHandlerFunc(grpcServer, mux)</code> that will connect my server to the following code, as explained here (<a href="https://grpc.io/blog/coreos" rel="nofollow noreferrer"> gRPC with open API </a>)</p>
  <pre><code>func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      // TODO(tamird): point to merged gRPC code rather than a PR.
      // This is a partial recreation of gRPC's internal checks https://github.com/grpc/grpc-go/pull/514/files#diff-95e9a25b738459a2d3030e1e6fa2a718R61
      util.P(&quot;ResponseFunction: GRPC: &quot;,r.URL) // simple fmt.PrintF(a ... interface)
      if r.ProtoMajor == 2 &amp;&amp; strings.Contains(r.Header.Get(&quot;Content-Type&quot;), &quot;application/grpc&quot;) {
          grpcServer.ServeHTTP(w, r)
      } else {
          otherHandler.ServeHTTP(w, r)
      }
  })
  }
  </code></pre>
  <p>The above code will run my Service running from my <code>mux</code> i.e connecting to http, but it won't run services from gRPC, i.e is connecting to my Android Device.</p>
  <p>I believe it requires, <code>TLS</code> connection, but I don't want to get into the implementation of securing my web and Android side code, as that would require me to change all the code at my Android Side and Web, which I want to avoid.</p>
  <p>So I am looking for a way to connect this <code>grpcServer</code> to my current <code>serverStruct</code> without using any <code>TLS</code> configuration.</p>
  <p><b>More Over myResearcH:</b>
  I have also searched there is a <code>repo</code> called <code>cmux</code> (<a href="https://github.com/soheilhy/cmux" rel="nofollow noreferrer">Connection Mux</a>) which will do the same job, but I don't understand how would I use it with my current <code>serverStruct</code>, as I have a fully functional web app running on  this, and I just need to add <code>gRPC</code> with my current code.</p>