With same port, my server not only for http, but also for tcp.
So I used function func NewServerConn(c net.Conn, r *bufio.Reader) *ServerConn to create httputil.ServerCoon by net.Conn
but as doc:
ServerConn is an artifact of Go's early HTTP implementation. It is low-level, old, and unused by Go's current HTTP stack. We should have deleted it before Go 1.
Deprecated: Use the Server in package net/http instead.
I don’t know which struct could be used to replace httputil.ServerConn.
What can I do?
So today you have something that accepts a connection, determines somehow if it’s a telnet or HTTP connection, and passes it to either httputil.NewServerConn or something else? First of all, if this works, go with it. ServerConn may be deprecated, but it has to be around “forever” due to the compatibility promise. It may not be the most beautiful thing to depend on, but honestly this thing is a bit of a hack to begin with anyway.
The other way to do it would be to wire up a custom net.Listener. One could imagine one where Accept() just wraps another (real) listeners Accept, and if the socket is supposed to become a telnet socket send it on a channel and Accept() again instead of returning. When the socket should become a HTTP socket, return it as usual to the http.Server that called Accept().
You could also make a net.Listener where you can register patterns of some kind and get back another listener that only returns sockets matching. You then split your listener into one that returns HTTP sockets and give that to a http.Server, and another listener that you give to your telnet loop.
If you need to read from the connections to determine what they are, you’ll need to wrap the connections in something when passing them on so the next thing to read from them also gets the initial bytes.