mirror of
https://github.com/soheilhy/cmux.git
synced 2024-11-10 03:31:52 +08:00
Add Go RPC in the README example
This commit is contained in:
parent
2e42ad4f75
commit
0417b90d39
10
README.md
10
README.md
@ -18,9 +18,11 @@ if err != nil {
|
|||||||
// Create a cmux.
|
// Create a cmux.
|
||||||
m := cmux.New(l)
|
m := cmux.New(l)
|
||||||
|
|
||||||
// Match connections in order.
|
// Match connections in order:
|
||||||
|
// First grpc, then HTTP, and otherwise Go RPC/TCP.
|
||||||
grpcL := m.Match(cmux.HTTP2HeaderField("content-type", "application/grpc"))
|
grpcL := m.Match(cmux.HTTP2HeaderField("content-type", "application/grpc"))
|
||||||
httpL := m.Match(cmux.Any()) // Any means anything that is not yet matched.
|
httpL := m.Match(cmux.HTTP1Fast())
|
||||||
|
trpcL := m.Match(cmux.Any()) // Any means anything that is not yet matched.
|
||||||
|
|
||||||
// Create your protocol servers.
|
// Create your protocol servers.
|
||||||
grpcS := grpc.NewServer()
|
grpcS := grpc.NewServer()
|
||||||
@ -30,9 +32,13 @@ httpS := &http.Server{
|
|||||||
Handler: &helloHTTP1Handler{},
|
Handler: &helloHTTP1Handler{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trpcS := rpc.NewServer()
|
||||||
|
s.Register(&ExampleRPCRcvr{})
|
||||||
|
|
||||||
// Use the muxed listeners for your servers.
|
// Use the muxed listeners for your servers.
|
||||||
go grpcS.Serve(grpcL)
|
go grpcS.Serve(grpcL)
|
||||||
go httpS.Serve(httpL)
|
go httpS.Serve(httpL)
|
||||||
|
go trpcS.Accept(trpcL)
|
||||||
|
|
||||||
// Start serving!
|
// Start serving!
|
||||||
m.Serve()
|
m.Serve()
|
||||||
|
Loading…
Reference in New Issue
Block a user