Browse Source

Pre-compile routes at Serve() time

I originally exposed Compile() for exactly this use case, but apparently
I never actually implemented this. Oops.

In any event, this makes the first request a little faster (an extremely
unscientific test suggests on the order of 10 microseconds). Also, if
something goes terribly wrong during route compilation, it would fail
before we start listening on the socket.
Carl Jackson 11 years ago
parent
commit
a655411f38
2 changed files with 2 additions and 0 deletions
  1. +1
    -0
      serve.go
  2. +1
    -0
      serve_appengine.go

+ 1
- 0
serve.go View File

@ -24,6 +24,7 @@ func Serve() {
flag.Parse() flag.Parse()
} }
DefaultMux.Compile()
// Install our handler at the root of the standard net/http default mux. // Install our handler at the root of the standard net/http default mux.
// This allows packages like expvar to continue working as expected. // This allows packages like expvar to continue working as expected.
http.Handle("/", DefaultMux) http.Handle("/", DefaultMux)


+ 1
- 0
serve_appengine.go View File

@ -6,6 +6,7 @@ import "net/http"
// Serve starts Goji using reasonable defaults. // Serve starts Goji using reasonable defaults.
func Serve() { func Serve() {
DefaultMux.Compile()
// Install our handler at the root of the standard net/http default mux. // Install our handler at the root of the standard net/http default mux.
// This is required for App Engine, and also allows packages like expvar // This is required for App Engine, and also allows packages like expvar
// to continue working as expected. // to continue working as expected.


Loading…
Cancel
Save