change function name

NewServerConn->Server
NewClientConn->Client
merge_conn
fangdingjun 6 years ago
parent 503997660b
commit 68c8ece2c6

@ -34,8 +34,8 @@ type ClientConn struct {
err error err error
} }
// NewClientConn create http2 client // Client create http2 client
func NewClientConn(c net.Conn) (*ClientConn, error) { func Client(c net.Conn) (*ClientConn, error) {
conn := &ClientConn{ conn := &ClientConn{
conn: c, streams: make(map[int]*ClientStream), conn: c, streams: make(map[int]*ClientStream),
lock: new(sync.Mutex), lock: new(sync.Mutex),
@ -272,15 +272,15 @@ type ServerConn struct {
// } // }
// srv.ServeTLS(l, "server.crt", "server.key") // srv.ServeTLS(l, "server.crt", "server.key")
func HTTP2Handler(srv *http.Server, conn *tls.Conn, handler http.Handler) { func HTTP2Handler(srv *http.Server, conn *tls.Conn, handler http.Handler) {
h2conn, err := NewServerConn(conn, handler) h2conn, err := Server(conn, handler)
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }
h2conn.Run() h2conn.Run()
} }
// NewServerConn create new server connection // Server create new server connection
func NewServerConn(c net.Conn, handler http.Handler) (*ServerConn, error) { func Server(c net.Conn, handler http.Handler) (*ServerConn, error) {
conn := &ServerConn{ conn := &ServerConn{
conn: c, conn: c,
Handler: handler, Handler: handler,

@ -35,7 +35,7 @@ server example
if err != nil { if err != nil {
break break
} }
h2conn, err := NewServerConn(c, nil) h2conn, err := Server(c, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -59,7 +59,7 @@ client example
t.Fatal("no http2 on server") t.Fatal("no http2 on server")
} }
h2conn, err := NewClientConn(conn) h2conn, err := Client(conn)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -29,7 +29,7 @@ func TestHttp2Client(t *testing.T) {
if cstate.NegotiatedProtocol != "h2" { if cstate.NegotiatedProtocol != "h2" {
t.Fatal("no http2 on server") t.Fatal("no http2 on server")
} }
h2conn, err := NewClientConn(conn) h2conn, err := Client(conn)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -102,7 +102,7 @@ func TestHttp2Server(t *testing.T) {
if err != nil { if err != nil {
break break
} }
h2conn, err := NewServerConn(c, nil) h2conn, err := Server(c, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

Loading…
Cancel
Save