Commit 8540a1c4 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: remove init func reference to ServeMux

Shrinks cmd/go by 30KB.

Change-Id: Ied31192e85af76ebac743f8cc12bd9ef6ec5048f
Reviewed-on: https://go-review.googlesource.com/20765Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
parent 826831ac
...@@ -84,8 +84,10 @@ func TestCmdGoNoHTTPServer(t *testing.T) { ...@@ -84,8 +84,10 @@ func TestCmdGoNoHTTPServer(t *testing.T) {
"net/http.(*Transport).RoundTrip": true, "net/http.(*Transport).RoundTrip": true,
// Verify these don't exist: // Verify these don't exist:
"net/http.http2Server": false, "net/http.http2Server": false,
"net/http.(*Server).Serve": false, "net/http.(*Server).Serve": false,
"net/http.(*ServeMux).ServeHTTP": false,
"net/http.DefaultServeMux": false,
} }
for sym, want := range wantSym { for sym, want := range wantSym {
got := bytes.Contains(out, []byte(sym)) got := bytes.Contains(out, []byte(sym))
......
...@@ -1800,10 +1800,12 @@ type muxEntry struct { ...@@ -1800,10 +1800,12 @@ type muxEntry struct {
} }
// NewServeMux allocates and returns a new ServeMux. // NewServeMux allocates and returns a new ServeMux.
func NewServeMux() *ServeMux { return &ServeMux{m: make(map[string]muxEntry)} } func NewServeMux() *ServeMux { return new(ServeMux) }
// DefaultServeMux is the default ServeMux used by Serve. // DefaultServeMux is the default ServeMux used by Serve.
var DefaultServeMux = NewServeMux() var DefaultServeMux = &defaultServeMux
var defaultServeMux ServeMux
// Does path match pattern? // Does path match pattern?
func pathMatch(pattern, path string) bool { func pathMatch(pattern, path string) bool {
...@@ -1926,6 +1928,9 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) { ...@@ -1926,6 +1928,9 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
panic("http: multiple registrations for " + pattern) panic("http: multiple registrations for " + pattern)
} }
if mux.m == nil {
mux.m = make(map[string]muxEntry)
}
mux.m[pattern] = muxEntry{explicit: true, h: handler, pattern: pattern} mux.m[pattern] = muxEntry{explicit: true, h: handler, pattern: pattern}
if pattern[0] != '/' { if pattern[0] != '/' {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment