← Home

cmux

Setup

CommandUse
l, _ := net.Listen("tcp", ":23456") m := cmux.New(l)Wrap the listener with cmux

Matching

CommandUse
grpcL := m.Match(cmux.HTTP2HeaderField("content-type", "application/grpc")) httpL := m.Match(cmux.HTTP1Fast()) anyL := m.Match(cmux.Any())Match listeners in order

Serving

CommandUse
go grpcS.Serve(grpcL) go httpS.Serve(httpL) go rpcS.Accept(anyL) m.Serve()Serve protocols from matched listeners