Using web.go on Google App Engine
In short, if you want to use web.go
in
Google App Engine's Go runtime environment, check out
my google-app-engine
branch of web.go
.
Using that one you can start using web.go
like this:
package webgoexample
import (
"http"
"log"
"os"
"web"
)
var server *web.Server
func init() {
server = &web.Server{
Config: web.Config,
Logger: log.New(os.Stdout, "", log.Ldate|log.Ltime)}
server.Get("/", func(ctx *web.Context) {
ctx.Write([]uint8("Hello from web.go!"))
})
// Send all requests to web.go.
http.HandleFunc("/", handler)
}
func handler(writer http.ResponseWriter, request *http.Request) {
server.ServeHTTP(writer, request)
}
BTW, if you simply put the web.go
branch in your root dir,
you have to remove the examples/
directory, otherwise App Engine won't be able to compile your
project.
The branch in question has quite minimal changes to web.go
, but I haven't
proposed to merge it to trunk yet, since it removes some functionality. First
of all I changed it not to set up /debug/
paths, so that I could remove the
use of http/pprof
, since it's not available on App Engine. After that I had
to also remove the use of net.ResolveTCPAddr
, which is also not available on
App Engine. I basically replaced it with net.SplitHostPort
, which I suspect
is good enough. It doesn't resolve host names and port names, but I'd be
surprised if hr.RemoteAddr
wouldn't be an IP address and a port number.