github.com/golazy/golazy@v0.0.7-0.20221012133820-968fe65a0b65/lazydev/protocolmux/doc.go (about)

     1  // protocolmux allows to peek the first bytes of a connection and decided to which handler forward the connection.
     2  /*
     3  
     4  	l, _ := net.Listen("tcp", addr)
     5  
     6  	// Initialize the muuxer
     7  	mux := &Mux{L: l}
     8  
     9  	// Create listeners just by setting the prefix
    10  	helloListener := mux.ListenTo([][]byte{[]byte("ping")})
    11  
    12  	for {
    13  		conn, _ := helloListener.Accept()
    14  		conn.Write("pong")
    15  		conn.Close();
    16  	}
    17  
    18  	// Or use one of the prefixes
    19  	go http.Serve(mux.ListenTo(HttpPrefix), nil) // Handle HTTP
    20  	go http.ServeTLS(mux.ListenTo(TLSPrefix), nil,...) // Handle HTTPS
    21  
    22  
    23  */
    24  package protocolmux